Files
mem0/mem0-ts/src/oss
Soumil RathiandClaude Opus 4.6 59880a6f8f feat: TS SDK v3 port, graph store removal, client v3 API migration
TypeScript SDK v3 pipeline (full parity with Python):
- Single-pass additive extraction with ADDITIVE_EXTRACTION_PROMPT
- Hybrid search (semantic + BM25 + entity boost) with additive scoring
- 8-phase batch pipeline (batch embed, persist, entity linking)
- New utils: scoring.ts, lemmatization.ts (natural), entity_extraction.ts (compromise)
- keywordSearch() on 8 vector stores (3 full: PGVector, Memory, Azure AI Search)
- Message persistence in SQLiteManager (rolling window of 10)
- Entity store as second vector collection
- MAX_BATCH=100 chunking guard on OpenAI/Azure embedBatch
- Updated default LLM model to gpt-4.1-nano-2025-04-14
- compromise + natural added as peer dependencies

Graph store removal (Python + TypeScript):
- Removed Neo4j, Memgraph, Kuzu, Neptune, Apache AGE integrations
- Deleted 18 graph-related files across both SDKs
- Removed GraphStoreFactory, GraphStoreConfig, graph_store config field
- Removed "relations" key from all API responses
- Removed graph optional dependency group from pyproject.toml
- Removed neo4j-driver from TS peerDependencies
- Simplified add/search/delete/reset (no more parallel graph operations)

Client SDK v3 API migration:
- add() endpoint: /v1/memories/ -> /v3/memories/ (async response)
- search() endpoint: /v2/memories/search/ -> /v3/memories/search/
- Removed output_format injection and v1.1 unwrapping logic
- Applied to both Python (sync + async) and TypeScript clients

Review feedback fixes:
- Removed deprecated custom_update_memory_prompt from MemoryConfig
- Added MAX_BATCH=100 chunking to Python + TS embed_batch
- Moved all inline imports to top level in main.py
- Cleaned up GraphStoreError dead code from exceptions.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:45:40 -07:00
..
2025-02-27 15:19:17 -08:00
2025-02-27 15:19:17 -08:00
2025-02-27 15:19:17 -08:00
2025-02-27 15:19:17 -08:00

mem0-ts

A TypeScript implementation of the mem0 memory system, using OpenAI for embeddings and completions.

Features

  • Memory storage and retrieval using vector embeddings
  • Fact extraction from text using GPT-4
  • SQLite-based history tracking
  • Optional graph-based memory relationships
  • TypeScript type safety
  • Built-in OpenAI integration with default configuration
  • In-memory vector store implementation
  • Extensible architecture with interfaces for custom implementations

Installation

  1. Clone the repository:
git clone <repository-url>
cd mem0-ts
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your OpenAI API key
  1. Build the project:
npm run build

Usage

Basic Example

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");

Default Configuration

The memory system comes with sensible defaults:

  • OpenAI embeddings with text-embedding-3-small model
  • In-memory vector store
  • OpenAI GPT-4 Turbo for LLM operations
  • SQLite for history tracking

You only need to provide API keys - all other settings are optional.

Methods

  • 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>

Try the Example

We provide a comprehensive example in examples/basic.ts that demonstrates all the features including:

  • Default configuration usage
  • In-memory vector store
  • PGVector store (with PostgreSQL)
  • Qdrant vector store
  • Redis vector store
  • Memory operations (add, search, update, delete)

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:

  • Different vector store configurations
  • Various memory operations
  • Error handling
  • Environment variable usage

Development

  1. Build the project:
npm run build
  1. Clean build files:
npm run clean

Extending

The system is designed to be extensible. You can implement your own:

  • Embedders by implementing the Embedder interface
  • Vector stores by implementing the VectorStore interface
  • Language models by implementing the LLM interface

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request