From ee00bd5731da56e866983b8eaa52ac6822c7a5b5 Mon Sep 17 00:00:00 2001 From: Parshva Daftari <89991302+parshvadaftari@users.noreply.github.com> Date: Sat, 23 Aug 2025 02:53:26 +0530 Subject: [PATCH] Fix typescript docs (#3357) --- docs/changelog.mdx | 41 ++++++--- .../components/embedders/models/google_AI.mdx | 30 ++++++- .../components/embedders/models/langchain.mdx | 86 +++++++++++++++---- docs/components/embedders/models/ollama.mdx | 43 +++++++++- docs/components/llms/models/langchain.mdx | 38 ++++---- docs/components/llms/models/ollama.mdx | 30 ++++++- docs/components/vectordbs/dbs/pgvector.mdx | 36 +++++++- 7 files changed, 246 insertions(+), 58 deletions(-) diff --git a/docs/changelog.mdx b/docs/changelog.mdx index 81b0cf300..947d4416b 100644 --- a/docs/changelog.mdx +++ b/docs/changelog.mdx @@ -7,9 +7,9 @@ mode: "wide" - + -**New Features:** +**New Features & Updates:** - **Pinecone:** Added namespace support and improved type safety - **Milvus:** Added db_name field to MilvusDBConfig - **Vector Stores:** Added multi-id filters support @@ -19,17 +19,36 @@ mode: "wide" - **LLM Monitoring:** Added monitoring callback support **Improvements:** -- **Performance:** Improved async handling in AsyncMemory class -- **Documentation:** Added async add announcement, personalized search docs, Neptune examples, V5 migration docs -- **Configuration:** Refactored base class config for LLMs, added sslmode for pgvector -- **Dependencies:** Updated psycopg to version 3, updated Docker compose +- **Performance:** + - Improved async handling in AsyncMemory class +- **Documentation:** + - Added async add announcement + - Added personalized search docs + - Added Neptune examples + - Added V5 migration docs +- **Configuration:** + - Refactored base class config for LLMs + - Added sslmode for pgvector +- **Dependencies:** + - Updated psycopg to version 3 + - Updated Docker compose **Bug Fixes:** -- **Tests:** Fixed failing tests and restricted package versions -- **Memgraph:** Fixed async attribute errors, n_embeddings usage, and indexing issues -- **Vector Stores:** Fixed Qdrant cloud indexing, Neo4j Cypher syntax, and LLM parameters -- **Graph Store:** Fixed LM config prioritization -- **Dependencies:** Fixed JSON import for psycopg +- **Tests:** + - Fixed failing tests + - Restricted package versions +- **Memgraph:** + - Fixed async attribute errors + - Fixed n_embeddings usage + - Fixed indexing issues +- **Vector Stores:** + - Fixed Qdrant cloud indexing + - Fixed Neo4j Cypher syntax + - Fixed LLM parameters +- **Graph Store:** + - Fixed LM config prioritization +- **Dependencies:** + - Fixed JSON import for psycopg **Refactoring:** - **Google AI:** Refactored from Gemini to Google AI diff --git a/docs/components/embedders/models/google_AI.mdx b/docs/components/embedders/models/google_AI.mdx index 7ce9024d3..9efd41b2e 100644 --- a/docs/components/embedders/models/google_AI.mdx +++ b/docs/components/embedders/models/google_AI.mdx @@ -6,7 +6,8 @@ To use Google AI embedding models, set the `GOOGLE_API_KEY` environment variable ### Usage -```python + +```python Python import os from mem0 import Memory @@ -26,12 +27,37 @@ m = Memory.from_config(config) messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, - {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] m.add(messages, user_id="john") ``` +```typescript TypeScript +import { Memory } from 'mem0ai/oss'; + +const config = { + embedder: { + provider: 'google', + config: { + apiKey: process.env.GOOGLE_API_KEY || '', + model: 'text-embedding-004', + // The output dimensionality is fixed at 768 for Google AI embeddings + }, + }, +}; + +const memory = new Memory(config); +const messages = [ + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} +] +await memory.add(messages, { userId: "john" }); +``` + + ### Config Here are the parameters available for configuring Gemini embedder: diff --git a/docs/components/embedders/models/langchain.mdx b/docs/components/embedders/models/langchain.mdx index aa48ae265..74ad18573 100644 --- a/docs/components/embedders/models/langchain.mdx +++ b/docs/components/embedders/models/langchain.mdx @@ -44,29 +44,33 @@ m.add(messages, user_id="alice", metadata={"category": "movies"}) ``` ```typescript TypeScript -import { Memory } from "mem0ai"; +import { Memory } from 'mem0ai/oss'; import { OpenAIEmbeddings } from "@langchain/openai"; -const embeddings = new OpenAIEmbeddings(); +// Initialize a LangChain embeddings model directly +const openaiEmbeddings = new OpenAIEmbeddings({ + modelName: "text-embedding-3-small", + dimensions: 1536, + apiKey: process.env.OPENAI_API_KEY, +}); + const config = { - "embedder": { - "provider": "langchain", - "config": { - "model": embeddings - } - } -} + embedder: { + provider: 'langchain', + config: { + model: openaiEmbeddings, + }, + }, +}; const memory = new Memory(config); - const messages = [ - { role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" }, - { role: "assistant", content: "How about a thriller movies? They can be quite engaging." }, - { role: "user", content: "I'm not a big fan of thriller movies but I love sci-fi movies." }, - { role: "assistant", content: "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future." } + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] - -memory.add(messages, user_id="alice", metadata={"category": "movies"}) +await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); ``` @@ -96,9 +100,10 @@ When using LangChain as an embedder provider, you'll need to: ### Examples with Different Providers + #### HuggingFace Embeddings -```python +```python Python from langchain_huggingface import HuggingFaceEmbeddings # Initialize a HuggingFace embeddings model @@ -117,9 +122,33 @@ config = { } ``` +```typescript TypeScript +import { Memory } from 'mem0ai/oss'; +import { HuggingFaceEmbeddings } from "@langchain/community/embeddings/hf"; + +// Initialize a HuggingFace embeddings model +const hfEmbeddings = new HuggingFaceEmbeddings({ + modelName: "BAAI/bge-small-en-v1.5", + encode: { + normalize_embeddings: true, + }, +}); + +const config = { + embedder: { + provider: 'langchain', + config: { + model: hfEmbeddings, + }, + }, +}; +``` + + + #### Ollama Embeddings -```python +```python Python from langchain_ollama import OllamaEmbeddings # Initialize an Ollama embeddings model @@ -137,6 +166,27 @@ config = { } ``` +```typescript TypeScript +import { Memory } from 'mem0ai/oss'; +import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama"; + +// Initialize an Ollama embeddings model +const ollamaEmbeddings = new OllamaEmbeddings({ + model: "nomic-embed-text", + baseUrl: "http://localhost:11434", // Ollama server URL +}); + +const config = { + embedder: { + provider: 'langchain', + config: { + model: ollamaEmbeddings, + }, + }, +}; +``` + + Make sure to install the necessary LangChain packages and any provider-specific dependencies. diff --git a/docs/components/embedders/models/ollama.mdx b/docs/components/embedders/models/ollama.mdx index d2829a8ee..4e1a4d331 100644 --- a/docs/components/embedders/models/ollama.mdx +++ b/docs/components/embedders/models/ollama.mdx @@ -2,7 +2,8 @@ You can use embedding models from Ollama to run Mem0 locally. ### Usage -```python + +```python Python import os from mem0 import Memory @@ -21,18 +22,52 @@ m = Memory.from_config(config) messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, - {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] m.add(messages, user_id="john") ``` +```typescript TypeScript +import { Memory } from 'mem0ai/oss'; + +const config = { + embedder: { + provider: 'ollama', + config: { + model: 'nomic-embed-text:latest', // or any other Ollama embedding model + url: 'http://localhost:11434', // Ollama server URL + }, + }, +}; + +const memory = new Memory(config); +const messages = [ + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} +] +await memory.add(messages, { userId: "john" }); +``` + + ### Config Here are the parameters available for configuring Ollama embedder: + + | Parameter | Description | Default Value | | --- | --- | --- | -| `model` | The name of the OpenAI model to use | `nomic-embed-text` | +| `model` | The name of the Ollama model to use | `nomic-embed-text` | | `embedding_dims` | Dimensions of the embedding model | `512` | -| `ollama_base_url` | Base URL for ollama connection | `None` | \ No newline at end of file +| `ollama_base_url` | Base URL for ollama connection | `None` | + + +| Parameter | Description | Default Value | +| --- | --- | --- | +| `model` | The name of the Ollama model to use | `nomic-embed-text:latest` | +| `url` | Base URL for Ollama server | `http://localhost:11434` | + + \ No newline at end of file diff --git a/docs/components/llms/models/langchain.mdx b/docs/components/llms/models/langchain.mdx index c8f4eaa1f..624d86425 100644 --- a/docs/components/llms/models/langchain.mdx +++ b/docs/components/llms/models/langchain.mdx @@ -46,34 +46,34 @@ m.add(messages, user_id="alice", metadata={"category": "movies"}) ``` ```typescript TypeScript -import { Memory } from "mem0ai"; +import { Memory } from 'mem0ai/oss'; import { ChatOpenAI } from "@langchain/openai"; -const openai_model = new ChatOpenAI({ - model: "gpt-4o", +// Initialize a LangChain model directly +const openaiModel = new ChatOpenAI({ + modelName: "gpt-4", temperature: 0.2, - max_tokens: 2000 -}) + maxTokens: 2000, + apiKey: process.env.OPENAI_API_KEY, +}); const config = { - "llm": { - "provider": "langchain", - "config": { - "model": openai_model - } - } -} + llm: { + provider: 'langchain', + config: { + model: openaiModel, + }, + }, +}; const memory = new Memory(config); - const messages = [ - { role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" }, - { role: "assistant", content: "How about a thriller movies? They can be quite engaging." }, - { role: "user", content: "I'm not a big fan of thriller movies but I love sci-fi movies." }, - { role: "assistant", content: "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future." } + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] - -memory.add(messages, user_id="alice", metadata={"category": "movies"}) +await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); ``` diff --git a/docs/components/llms/models/ollama.mdx b/docs/components/llms/models/ollama.mdx index 757fd2cc0..9c0cd73cf 100644 --- a/docs/components/llms/models/ollama.mdx +++ b/docs/components/llms/models/ollama.mdx @@ -2,7 +2,8 @@ You can use LLMs from Ollama to run Mem0 locally. These [models](https://ollama. ## Usage -```python + +```python Python import os from mem0 import Memory @@ -23,12 +24,37 @@ m = Memory.from_config(config) messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, - {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] m.add(messages, user_id="alice", metadata={"category": "movies"}) ``` +```typescript TypeScript +import { Memory } from 'mem0ai/oss'; + +const config = { + llm: { + provider: 'ollama', + config: { + model: 'llama3.1:8b', // or any other Ollama model + url: 'http://localhost:11434', // Ollama server URL + temperature: 0.1, + }, + }, +}; + +const memory = new Memory(config); +const messages = [ + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} +] +await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); +``` + + ## Config All available parameters for the `ollama` config are present in [Master List of All Params in Config](../config). \ No newline at end of file diff --git a/docs/components/vectordbs/dbs/pgvector.mdx b/docs/components/vectordbs/dbs/pgvector.mdx index 6a083af5c..03836c2db 100644 --- a/docs/components/vectordbs/dbs/pgvector.mdx +++ b/docs/components/vectordbs/dbs/pgvector.mdx @@ -2,7 +2,8 @@ ### Usage -```python + +```python Python import os from mem0 import Memory @@ -24,12 +25,43 @@ m = Memory.from_config(config) messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, - {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] m.add(messages, user_id="alice", metadata={"category": "movies"}) ``` +```typescript TypeScript +import { Memory } from 'mem0ai/oss'; + +const config = { + vectorStore: { + provider: 'pgvector', + config: { + collectionName: 'memories', + embeddingModelDims: 1536, + user: 'test', + password: '123', + host: '127.0.0.1', + port: 5432, + dbname: 'vector_store', // Optional, defaults to 'postgres' + diskann: false, // Optional, requires pgvectorscale extension + hnsw: false, // Optional, for HNSW indexing + }, + }, +}; + +const memory = new Memory(config); +const messages = [ + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} +] +await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); +``` + + ### Config Here's the parameters available for configuring pgvector: