|
| 1 | +--- |
| 2 | +title: Baidu VectorDB (Mochow) |
| 3 | +--- |
| 4 | + |
| 5 | +[Baidu VectorDB](https://cloud.baidu.com/doc/VDB/index.html) is an enterprise-level distributed vector database service developed by Baidu Intelligent Cloud. It is powered by Baidu's proprietary "Mochow" vector database kernel, providing high performance, availability, and security for vector search. |
| 6 | + |
| 7 | +### Usage |
| 8 | + |
| 9 | +```python |
| 10 | +import os |
| 11 | +from mem0 import Memory |
| 12 | + |
| 13 | +config = { |
| 14 | + "vector_store": { |
| 15 | + "provider": "baidu", |
| 16 | + "config": { |
| 17 | + "endpoint": "http://your-mochow-endpoint:8287", |
| 18 | + "account": "root", |
| 19 | + "api_key": "your-api-key", |
| 20 | + "database_name": "mem0", |
| 21 | + "table_name": "mem0_table", |
| 22 | + "embedding_model_dims": 1536, |
| 23 | + "metric_type": "COSINE" |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +m = Memory.from_config(config) |
| 29 | +messages = [ |
| 30 | + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| 31 | + {"role": "assistant", "content": "How about a thriller movie? They can be quite engaging."}, |
| 32 | + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| 33 | + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| 34 | +] |
| 35 | +m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| 36 | +``` |
| 37 | + |
| 38 | +### Config |
| 39 | + |
| 40 | +Here are the available parameters for the `mochow` config: |
| 41 | + |
| 42 | +| Parameter | Description | Default Value | |
| 43 | +| --- | --- | --- | |
| 44 | +| `endpoint` | Endpoint URL for your Baidu VectorDB instance | Required | |
| 45 | +| `account` | Baidu VectorDB account name | `root` | |
| 46 | +| `api_key` | API key for accessing Baidu VectorDB | Required | |
| 47 | +| `database_name` | Name of the database | `mem0` | |
| 48 | +| `table_name` | Name of the table | `mem0_table` | |
| 49 | +| `embedding_model_dims` | Dimensions of the embedding model | `1536` | |
| 50 | +| `metric_type` | Distance metric for similarity search | `L2` | |
| 51 | + |
| 52 | +### Distance Metrics |
| 53 | + |
| 54 | +The following distance metrics are supported: |
| 55 | + |
| 56 | +- `L2`: Euclidean distance (default) |
| 57 | +- `IP`: Inner product |
| 58 | +- `COSINE`: Cosine similarity |
| 59 | + |
| 60 | +### Index Configuration |
| 61 | + |
| 62 | +The vector index is automatically configured with the following HNSW parameters: |
| 63 | + |
| 64 | +- `m`: 16 (number of connections per element) |
| 65 | +- `efconstruction`: 200 (size of the dynamic candidate list) |
| 66 | +- `auto_build`: true (automatically build index) |
| 67 | +- `auto_build_index_policy`: Incremental build with 10000 rows increment |
0 commit comments