This implementation adds a Node.js SDK and HTTP server for Memvid, enabling integration with serverless platforms (Vercel, AWS Lambda) and voice agents (Grok Voice Agent).
┌─────────────────────────────────────────────────────────────┐
│ Serverless Environment │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Grok Voice Agent + Node.js SDK (Vercel/Lambda) │ │
│ │ • Function calling pattern │ │
│ │ • WebSocket for real-time audio │ │
│ │ • @memvid/sdk for memory access │ │
│ └────────────────────┬─────────────────────────────────┘ │
│ │ HTTP/JSON │
│ ▼ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Memvid Server (Rust - Axum) │ │
│ │ • Session management │ │
│ │ • REST API (JSON) │ │
│ │ • Multi-tenant architecture │ │
│ └────────────────────┬─────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────┐ │
│ │ .mv2 Files │ │
│ │ (Storage) │ │
│ └────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Purpose: Expose Memvid functionality via HTTP/JSON API
Files:
crates/memvid-server/Cargo.toml- Dependencies and configurationcrates/memvid-server/src/lib.rs- HTTP API implementationcrates/memvid-server/src/bin/memvid-server.rs- Server binary
Features:
- ✅ Session-based multi-tenancy
- ✅ RESTful API design
- ✅ JSON request/response
- ✅ Error handling with proper HTTP status codes
- ✅ CORS support
- ✅ Tracing and logging
API Endpoints:
POST /api/v1/sessions Create session
GET /api/v1/sessions/:id Get session info
DELETE /api/v1/sessions/:id Close session
POST /api/v1/sessions/:id/store Store data
POST /api/v1/sessions/:id/search Search memory
POST /api/v1/sessions/:id/ask RAG query
GET /api/v1/sessions/:id/timeline Get timeline
POST /api/v1/sessions/:id/commit Commit changes
GET /health Health check
Purpose: TypeScript client for the Memvid HTTP server
Files:
packages/memvid-js/package.json- Package configurationpackages/memvid-js/tsconfig.json- TypeScript configurationpackages/memvid-js/src/index.ts- Main exportspackages/memvid-js/src/types.ts- Type definitionspackages/memvid-js/src/client.ts- Client implementationpackages/memvid-js/test/client.test.ts- Unit testspackages/memvid-js/vitest.config.ts- Test configuration
Features:
- ✅ Full TypeScript support with type safety
- ✅ Async/await API
- ✅ Error handling with custom MemvidError class
- ✅ Timeout support
- ✅ Custom fetch implementation (for edge environments)
- ✅ Session management
- ✅ Comprehensive test suite
Usage Example:
import { MemvidClient } from '@memvid/sdk';
const client = new MemvidClient({
serverUrl: 'http://localhost:8080',
});
const session = await client.createSession({
storagePath: './memory.mv2',
createIfNotExists: true,
});
await session.store('Hello, world!', {
tags: ['greeting'],
labels: ['user'],
});
const results = await session.search({ query: 'hello', top_k: 5 });
console.log(results);
await session.close();Purpose: Vercel Edge Function for Grok Voice Agent integration
Files:
examples/vercel-grok/index.ts- Main webhook handlerexamples/vercel-grok/grok-tools.ts- Tool definitionsexamples/vercel-grok/README.md- Setup guideexamples/vercel-grok/package.json- Dependencies
Features:
- ✅ WebSocket event handling
- ✅ Function call routing
- ✅ Auto-transcription storage
- ✅ Context retrieval
- ✅ RAG question answering
- ✅ Deployment ready
Available Tools:
search_memory- Search conversation historyget_context- Get recent messagesask_question- RAG-based question answeringstore_conversation- Store important information
Integration Flow:
Grok Voice Agent Vercel Function Memvid Server
│ │ │
│ WebSocket Event │ │
├─────────────────────────────────>│ │
│ (function call) │ HTTP Request │
│ ├───────────────────────────>│
│ │ │ Search
│ │ │ Query
│ │ HTTP Response │ Result
│ │<───────────────────────────┤
│ Function Result │ │
│<─────────────────────────────────┤ │
│ │ │
# Build and run the server
cargo run --bin memvid-server
# Server will start on http://localhost:8080cd packages/memvid-js
# Install dependencies
npm install
# Build TypeScript
npm run build
# Test
npm testnode -e "
const { MemvidClient } = require('./dist/index.js');
async function main() {
const client = new MemvidClient({
serverUrl: 'http://localhost:8080',
});
const session = await client.createSession({
storagePath: './conversation.mv2',
createIfNotExists: true,
});
console.log('Session ID:', session.sessionId);
await session.store('Hello, my name is Alice', {
labels: ['user'],
tags: ['introduction'],
});
const results = await session.search({ query: 'Alice' });
console.log('Search results:', results);
await session.close();
}
main();
"cd examples/vercel-grok
# Install dependencies
npm install
# Set environment variables
export MEMVID_SERVER_URL=http://localhost:8080
export MEMVID_SESSION_ID=<your-session-id>
# Deploy to Vercel
vercel deploy# Test health endpoint
curl http://localhost:8080/health
# Create session
curl -X POST http://localhost:8080/api/v1/sessions \
-H "Content-Type: application/json" \
-d '{"storage_path": "./test.mv2", "create_if_not_exists": true}'
# Store data
curl -X POST http://localhost:8080/api/v1/sessions/{session_id}/store \
-H "Content-Type: application/json" \
-d '{"content": "SGVsbG8gd29ybGQ=", "options": {"tags": ["test"]}}'
# Search
curl -X POST http://localhost:8080/api/v1/sessions/{session_id}/search \
-H "Content-Type: application/json" \
-d '{"query": "hello", "top_k": 5}'cd packages/memvid-js
npm test# Test webhook
curl -X POST http://localhost:3000/api/grok-webhook \
-H "Content-Type: application/json" \
-d '{
"type": "response.function_call_arguments.done",
"call_id": "test_123",
"name": "search_memory",
"arguments": "{\"query\": \"hello\"}"
}'memvid/
├── Cargo.toml # Workspace root
├── crates/
│ ├── memvid-core/ # Core Memvid library
│ ├── memvid-adapter/ # Async adapter (existing)
│ └── memvid-server/ # HTTP server (NEW)
│ ├── Cargo.toml
│ ├── src/
│ │ ├── lib.rs # API implementation
│ │ └── bin/
│ │ └── memvid-server.rs # Server binary
├── packages/
│ └── memvid-js/ # Node.js SDK (NEW)
│ ├── package.json
│ ├── tsconfig.json
│ ├── vitest.config.ts
│ ├── src/
│ │ ├── index.ts # Main exports
│ │ ├── types.ts # Type definitions
│ │ └── client.ts # Client implementation
│ ├── test/
│ │ └── client.test.ts # Unit tests
│ └── examples/ # Example usage
├── examples/
│ └── vercel-grok/ # Grok integration (NEW)
│ ├── index.ts # Webhook handler
│ ├── grok-tools.ts # Tool definitions
│ ├── README.md # Setup guide
│ └── package.json
└── IMPLEMENTATION_SUMMARY.md # This file
Why: Serverless platforms don't support native Rust bindings
- ✅ Works with Vercel, AWS Lambda, Cloudflare Workers
- ✅ No native compilation per platform
- ✅ Easy to deploy and scale
- ✅ Clean separation of concerns
Why: Support multiple users and isolate data
- Each session has its own
.mv2file - Session IDs for easy management
- Multi-tenant architecture
- Per-session isolation
Why: Maximum compatibility
- Works with any language
- Standard HTTP infrastructure
- Easy to debug and test
- WebSocket compatible for real-time
Why: Type safety and DX
- Full IntelliSense support
- Compile-time error checking
- Easy integration with modern frameworks
- Good documentation through types
Why: Matches voice agent API design
- Native integration with Grok
- Easy to extend
- Standard pattern for AI agents
- WebSocket-friendly
MEMVID_BIND_ADDRESS- Bind address (default:0.0.0.0:8080)
MEMVID_SERVER_URL- Server URLMEMVID_API_KEY- Optional API keyMEMVID_SESSION_ID- Session ID (for webhook)
- Set in Vercel dashboard or
vercel envCLI
- Add API key authentication
- Implement rate limiting
- Add request validation
- Enable CORS for specific origins only
- Add connection pooling
- Implement caching layer
- Optimize for low latency
- Add compression
- Add health checks
- Implement metrics
- Add request logging
- Track error rates
- Horizontal scaling with load balancer
- Session distribution
- Shared storage backend
- Multi-region deployment
- Add Authentication: Implement API key or JWT auth
- Add Rate Limiting: Prevent abuse with token bucket
- Add Caching: Cache search results and sessions
- Add Metrics: Track usage and performance
- Add WebSocket Support: For real-time updates
- Add Load Testing: Verify performance under load
- Add CI/CD: Automated testing and deployment
- Documentation: API reference and guides
- Memvid Core: https://github.com/memvid/memvid
- Grok Voice Agent: https://x.ai/news/grok-voice-agent-api
- Vercel Edge Functions: https://vercel.com/docs/edge-functions
- Axum Framework: https://github.com/tokio-rs/axum
- TypeScript: https://www.typescriptlang.org/
Apache-2.0