Fix typescript docs (#3357)

This commit is contained in:
Parshva Daftari
2025-08-22 14:23:26 -07:00
committed by GitHub
parent f914dca659
commit ee00bd5731
7 changed files with 246 additions and 58 deletions
+30 -11
View File
@@ -7,9 +7,9 @@ mode: "wide"
<Tabs> <Tabs>
<Tab title="Python"> <Tab title="Python">
<Update label="2025-07-24" description="v0.1.116"> <Update label="2025-08-14" description="v0.1.116">
**New Features:** **New Features & Updates:**
- **Pinecone:** Added namespace support and improved type safety - **Pinecone:** Added namespace support and improved type safety
- **Milvus:** Added db_name field to MilvusDBConfig - **Milvus:** Added db_name field to MilvusDBConfig
- **Vector Stores:** Added multi-id filters support - **Vector Stores:** Added multi-id filters support
@@ -19,17 +19,36 @@ mode: "wide"
- **LLM Monitoring:** Added monitoring callback support - **LLM Monitoring:** Added monitoring callback support
**Improvements:** **Improvements:**
- **Performance:** Improved async handling in AsyncMemory class - **Performance:**
- **Documentation:** Added async add announcement, personalized search docs, Neptune examples, V5 migration docs - Improved async handling in AsyncMemory class
- **Configuration:** Refactored base class config for LLMs, added sslmode for pgvector - **Documentation:**
- **Dependencies:** Updated psycopg to version 3, updated Docker compose - 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:** **Bug Fixes:**
- **Tests:** Fixed failing tests and restricted package versions - **Tests:**
- **Memgraph:** Fixed async attribute errors, n_embeddings usage, and indexing issues - Fixed failing tests
- **Vector Stores:** Fixed Qdrant cloud indexing, Neo4j Cypher syntax, and LLM parameters - Restricted package versions
- **Graph Store:** Fixed LM config prioritization - **Memgraph:**
- **Dependencies:** Fixed JSON import for psycopg - 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:** **Refactoring:**
- **Google AI:** Refactored from Gemini to Google AI - **Google AI:** Refactored from Gemini to Google AI
+28 -2
View File
@@ -6,7 +6,8 @@ To use Google AI embedding models, set the `GOOGLE_API_KEY` environment variable
### Usage ### Usage
```python <CodeGroup>
```python Python
import os import os
from mem0 import Memory from mem0 import Memory
@@ -26,12 +27,37 @@ m = Memory.from_config(config)
messages = [ messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"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": "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."} {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
] ]
m.add(messages, user_id="john") 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" });
```
</CodeGroup>
### Config ### Config
Here are the parameters available for configuring Gemini embedder: Here are the parameters available for configuring Gemini embedder:
+68 -18
View File
@@ -44,29 +44,33 @@ m.add(messages, user_id="alice", metadata={"category": "movies"})
``` ```
```typescript TypeScript ```typescript TypeScript
import { Memory } from "mem0ai"; import { Memory } from 'mem0ai/oss';
import { OpenAIEmbeddings } from "@langchain/openai"; 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 = { const config = {
"embedder": { embedder: {
"provider": "langchain", provider: 'langchain',
"config": { config: {
"model": embeddings model: openaiEmbeddings,
} },
} },
} };
const memory = new Memory(config); const memory = new Memory(config);
const messages = [ const messages = [
{ role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" }, {"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": "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." } {"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" } });
memory.add(messages, user_id="alice", metadata={"category": "movies"})
``` ```
</CodeGroup> </CodeGroup>
@@ -96,9 +100,10 @@ When using LangChain as an embedder provider, you'll need to:
### Examples with Different Providers ### Examples with Different Providers
<CodeGroup>
#### HuggingFace Embeddings #### HuggingFace Embeddings
```python ```python Python
from langchain_huggingface import HuggingFaceEmbeddings from langchain_huggingface import HuggingFaceEmbeddings
# Initialize a HuggingFace embeddings model # 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,
},
},
};
```
</CodeGroup>
<CodeGroup>
#### Ollama Embeddings #### Ollama Embeddings
```python ```python Python
from langchain_ollama import OllamaEmbeddings from langchain_ollama import OllamaEmbeddings
# Initialize an Ollama embeddings model # 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,
},
},
};
```
</CodeGroup>
<Note> <Note>
Make sure to install the necessary LangChain packages and any provider-specific dependencies. Make sure to install the necessary LangChain packages and any provider-specific dependencies.
</Note> </Note>
+39 -4
View File
@@ -2,7 +2,8 @@ You can use embedding models from Ollama to run Mem0 locally.
### Usage ### Usage
```python <CodeGroup>
```python Python
import os import os
from mem0 import Memory from mem0 import Memory
@@ -21,18 +22,52 @@ m = Memory.from_config(config)
messages = [ messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"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": "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."} {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
] ]
m.add(messages, user_id="john") 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" });
```
</CodeGroup>
### Config ### Config
Here are the parameters available for configuring Ollama embedder: Here are the parameters available for configuring Ollama embedder:
<Tabs>
<Tab title="Python">
| Parameter | Description | Default Value | | 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` | | `embedding_dims` | Dimensions of the embedding model | `512` |
| `ollama_base_url` | Base URL for ollama connection | `None` | | `ollama_base_url` | Base URL for ollama connection | `None` |
</Tab>
<Tab title="TypeScript">
| 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` |
</Tab>
</Tabs>
+19 -19
View File
@@ -46,34 +46,34 @@ m.add(messages, user_id="alice", metadata={"category": "movies"})
``` ```
```typescript TypeScript ```typescript TypeScript
import { Memory } from "mem0ai"; import { Memory } from 'mem0ai/oss';
import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenAI } from "@langchain/openai";
const openai_model = new ChatOpenAI({ // Initialize a LangChain model directly
model: "gpt-4o", const openaiModel = new ChatOpenAI({
modelName: "gpt-4",
temperature: 0.2, temperature: 0.2,
max_tokens: 2000 maxTokens: 2000,
}) apiKey: process.env.OPENAI_API_KEY,
});
const config = { const config = {
"llm": { llm: {
"provider": "langchain", provider: 'langchain',
"config": { config: {
"model": openai_model model: openaiModel,
} },
} },
} };
const memory = new Memory(config); const memory = new Memory(config);
const messages = [ const messages = [
{ role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" }, {"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": "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." } {"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" } });
memory.add(messages, user_id="alice", metadata={"category": "movies"})
``` ```
</CodeGroup> </CodeGroup>
+28 -2
View File
@@ -2,7 +2,8 @@ You can use LLMs from Ollama to run Mem0 locally. These [models](https://ollama.
## Usage ## Usage
```python <CodeGroup>
```python Python
import os import os
from mem0 import Memory from mem0 import Memory
@@ -23,12 +24,37 @@ m = Memory.from_config(config)
messages = [ messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"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": "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."} {"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"}) 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" } });
```
</CodeGroup>
## Config ## Config
All available parameters for the `ollama` config are present in [Master List of All Params in Config](../config). All available parameters for the `ollama` config are present in [Master List of All Params in Config](../config).
+34 -2
View File
@@ -2,7 +2,8 @@
### Usage ### Usage
```python <CodeGroup>
```python Python
import os import os
from mem0 import Memory from mem0 import Memory
@@ -24,12 +25,43 @@ m = Memory.from_config(config)
messages = [ messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"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": "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."} {"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"}) 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" } });
```
</CodeGroup>
### Config ### Config
Here's the parameters available for configuring pgvector: Here's the parameters available for configuring pgvector: