mem0-ts/src/oss/README.md
A TypeScript implementation of the mem0 memory system, using OpenAI for embeddings and completions.
git clone <repository-url>
cd mem0-ts
npm install
cp .env.example .env
# Edit .env with your OpenAI API key
npm run build
import { Memory } from "mem0-ts";
// Create a memory instance with default OpenAI configuration
const memory = new Memory();
// Or with minimal configuration (only API key)
const memory = new Memory({
embedder: {
config: {
apiKey: process.env.OPENAI_API_KEY,
},
},
llm: {
config: {
apiKey: process.env.OPENAI_API_KEY,
},
},
});
// Or with custom configuration
const memory = new Memory({
embedder: {
provider: "openai",
config: {
apiKey: process.env.OPENAI_API_KEY,
model: "text-embedding-3-small",
},
},
vectorStore: {
provider: "memory",
config: {
collectionName: "custom-memories",
},
},
llm: {
provider: "openai",
config: {
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4-turbo-preview",
},
},
});
// Add a memory
await memory.add("The sky is blue", "user123");
// Search memories
const results = await memory.search("What color is the sky?", "user123");
The memory system comes with sensible defaults:
text-embedding-3-small modelYou only need to provide API keys - all other settings are optional.
add(messages: string | Message[], userId?: string, ...): Promise<SearchResult>search(query: string, userId?: string, ...): Promise<SearchResult>get(memoryId: string): Promise<MemoryItem | null>update(memoryId: string, data: string): Promise<{ message: string }>delete(memoryId: string): Promise<{ message: string }>deleteAll(userId?: string, ...): Promise<{ message: string }>history(memoryId: string): Promise<any[]>reset(): Promise<void>We provide a comprehensive example in examples/basic.ts that demonstrates all the features including:
To run the example:
npm run example
You can use this example as a template and modify it according to your needs. The example includes:
npm run build
npm run clean
The system is designed to be extensible. You can implement your own:
Embedder interfaceVectorStore interfaceLLM interfaceMIT