repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | # mem0-ts |
| #2 | |
| #3 | A TypeScript implementation of the mem0 memory system, using OpenAI for embeddings and completions. |
| #4 | |
| #5 | ## Features |
| #6 | |
| #7 | - Memory storage and retrieval using vector embeddings |
| #8 | - Fact extraction from text using GPT-4 |
| #9 | - SQLite-based history tracking |
| #10 | - Optional graph-based memory relationships |
| #11 | - TypeScript type safety |
| #12 | - Built-in OpenAI integration with default configuration |
| #13 | - In-memory vector store implementation |
| #14 | - Extensible architecture with interfaces for custom implementations |
| #15 | |
| #16 | ## Installation |
| #17 | |
| #18 | 1. Clone the repository: |
| #19 | |
| #20 | ```bash |
| #21 | git clone <repository-url> |
| #22 | cd mem0-ts |
| #23 | ``` |
| #24 | |
| #25 | 2. Install dependencies: |
| #26 | |
| #27 | ```bash |
| #28 | npm install |
| #29 | ``` |
| #30 | |
| #31 | 3. Set up environment variables: |
| #32 | |
| #33 | ```bash |
| #34 | cp .env.example .env |
| #35 | # Edit .env with your OpenAI API key |
| #36 | ``` |
| #37 | |
| #38 | 4. Build the project: |
| #39 | |
| #40 | ```bash |
| #41 | npm run build |
| #42 | ``` |
| #43 | |
| #44 | ## Usage |
| #45 | |
| #46 | ### Basic Example |
| #47 | |
| #48 | ```typescript |
| #49 | import { Memory } from "mem0-ts"; |
| #50 | |
| #51 | // Create a memory instance with default OpenAI configuration |
| #52 | const memory = new Memory(); |
| #53 | |
| #54 | // Or with minimal configuration (only API key) |
| #55 | const memory = new Memory({ |
| #56 | embedder: { |
| #57 | config: { |
| #58 | apiKey: process.env.OPENAI_API_KEY, |
| #59 | }, |
| #60 | }, |
| #61 | llm: { |
| #62 | config: { |
| #63 | apiKey: process.env.OPENAI_API_KEY, |
| #64 | }, |
| #65 | }, |
| #66 | }); |
| #67 | |
| #68 | // Or with custom configuration |
| #69 | const memory = new Memory({ |
| #70 | embedder: { |
| #71 | provider: "openai", |
| #72 | config: { |
| #73 | apiKey: process.env.OPENAI_API_KEY, |
| #74 | model: "text-embedding-3-small", |
| #75 | }, |
| #76 | }, |
| #77 | vectorStore: { |
| #78 | provider: "memory", |
| #79 | config: { |
| #80 | collectionName: "custom-memories", |
| #81 | }, |
| #82 | }, |
| #83 | llm: { |
| #84 | provider: "openai", |
| #85 | config: { |
| #86 | apiKey: process.env.OPENAI_API_KEY, |
| #87 | model: "gpt-4-turbo-preview", |
| #88 | }, |
| #89 | }, |
| #90 | }); |
| #91 | |
| #92 | // Add a memory |
| #93 | await memory.add("The sky is blue", "user123"); |
| #94 | |
| #95 | // Search memories |
| #96 | const results = await memory.search("What color is the sky?", "user123"); |
| #97 | ``` |
| #98 | |
| #99 | ### Default Configuration |
| #100 | |
| #101 | The memory system comes with sensible defaults: |
| #102 | |
| #103 | - OpenAI embeddings with `text-embedding-3-small` model |
| #104 | - In-memory vector store |
| #105 | - OpenAI GPT-4 Turbo for LLM operations |
| #106 | - SQLite for history tracking |
| #107 | |
| #108 | You only need to provide API keys - all other settings are optional. |
| #109 | |
| #110 | ### Methods |
| #111 | |
| #112 | - `add(messages: string | Message[], userId?: string, ...): Promise<SearchResult>` |
| #113 | - `search(query: string, userId?: string, ...): Promise<SearchResult>` |
| #114 | - `get(memoryId: string): Promise<MemoryItem | null>` |
| #115 | - `update(memoryId: string, data: string): Promise<{ message: string }>` |
| #116 | - `delete(memoryId: string): Promise<{ message: string }>` |
| #117 | - `deleteAll(userId?: string, ...): Promise<{ message: string }>` |
| #118 | - `history(memoryId: string): Promise<any[]>` |
| #119 | - `reset(): Promise<void>` |
| #120 | |
| #121 | ### Try the Example |
| #122 | |
| #123 | We provide a comprehensive example in `examples/basic.ts` that demonstrates all the features including: |
| #124 | |
| #125 | - Default configuration usage |
| #126 | - In-memory vector store |
| #127 | - PGVector store (with PostgreSQL) |
| #128 | - Qdrant vector store |
| #129 | - Redis vector store |
| #130 | - Memory operations (add, search, update, delete) |
| #131 | |
| #132 | To run the example: |
| #133 | |
| #134 | ```bash |
| #135 | npm run example |
| #136 | ``` |
| #137 | |
| #138 | You can use this example as a template and modify it according to your needs. The example includes: |
| #139 | |
| #140 | - Different vector store configurations |
| #141 | - Various memory operations |
| #142 | - Error handling |
| #143 | - Environment variable usage |
| #144 | |
| #145 | ## Development |
| #146 | |
| #147 | 1. Build the project: |
| #148 | |
| #149 | ```bash |
| #150 | npm run build |
| #151 | ``` |
| #152 | |
| #153 | 2. Clean build files: |
| #154 | |
| #155 | ```bash |
| #156 | npm run clean |
| #157 | ``` |
| #158 | |
| #159 | ## Extending |
| #160 | |
| #161 | The system is designed to be extensible. You can implement your own: |
| #162 | |
| #163 | - Embedders by implementing the `Embedder` interface |
| #164 | - Vector stores by implementing the `VectorStore` interface |
| #165 | - Language models by implementing the `LLM` interface |
| #166 | |
| #167 | ## License |
| #168 | |
| #169 | MIT |
| #170 | |
| #171 | ## Contributing |
| #172 | |
| #173 | 1. Fork the repository |
| #174 | 2. Create your feature branch |
| #175 | 3. Commit your changes |
| #176 | 4. Push to the branch |
| #177 | 5. Create a new Pull Request |
| #178 |