Back to Mem0

Baidu VectorDB (Mochow)

docs/components/vectordbs/dbs/baidu.mdx

2.0.124.3 KB
Original Source

Baidu VectorDB 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.

Installation

<CodeGroup> ```bash Python pip install pymochow ```
bash
npm install @mochow/mochow-sdk-node
</CodeGroup>

Usage

python
from mem0 import Memory

config = {
    "vector_store": {
        "provider": "baidu",
        "config": {
            "endpoint": "http://your-mochow-endpoint:8287",
            "account": "root",
            "api_key": "your-api-key",
            "database_name": "mem0",
            "table_name": "mem0_table",
            "embedding_model_dims": 1536,
            "metric_type": "COSINE"
        }
    }
}

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 movie? 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."}
]
m.add(messages, user_id="alice", metadata={"category": "movies"})
typescript
import { Memory } from "mem0ai/oss";

const memory = new Memory({
  embedder: {
    provider: "openai",
    config: {
      apiKey: process.env.OPENAI_API_KEY || "",
      model: "text-embedding-3-small",
      embeddingDims: 1536,
    },
  },
  vectorStore: {
    provider: "baidu",
    config: {
      endpoint: process.env.BAIDU_ENDPOINT || "",
      account: process.env.BAIDU_ACCOUNT || "root",
      apiKey: process.env.BAIDU_API_KEY || "",
      databaseName: "mem0",
      tableName: "mem0_table",
      embeddingModelDims: 1536,
      metricType: "COSINE",
    },
  },
  llm: {
    provider: "openai",
    config: {
      apiKey: process.env.OPENAI_API_KEY || "",
      model: "gpt-5-mini",
    },
  },
});

Config

Here are the parameters available for configuring Baidu VectorDB:

ParameterDescriptionDefault Value
endpointEndpoint URL for your Baidu VectorDB instanceRequired
accountBaidu VectorDB account nameroot
api_keyAPI key for accessing Baidu VectorDBRequired
database_nameName of the databasemem0
table_nameName of the tablemem0
embedding_model_dimsDimensions of the embedding model1536
metric_typeDistance metric for similarity searchL2
clientPrebuilt Mochow client (TypeScript SDK only)None

For the TypeScript OSS SDK, use the camelCase equivalents:

  • databaseName
  • tableName
  • embeddingModelDims
  • metricType

For OSS TS usage, endpoint, account, apiKey, databaseName, tableName, and embeddingModelDims are required unless you inject a prebuilt client. metricType defaults to L2, matching the Python SDK.

Distance Metrics

The following distance metrics are supported:

  • L2: Euclidean distance (default)
  • IP: Inner product
  • COSINE: Cosine similarity

Index Configuration

The vector index is automatically configured with the following HNSW parameters:

  • m: 16 (number of connections per element)
  • efconstruction: 200 (size of the dynamic candidate list)
  • auto_build: true (automatically build index)
  • auto_build_index_policy: Incremental build with 10000 rows increment

The TypeScript provider also creates a BM25 inverted index over a textLemmatized column so keywordSearch() runs against a real full-text index. Mem0 lemmatizes the query before it reaches the vector store, so only the lemmatized form of each memory is indexed. If you point tableName at a table created before this index existed, keywordSearch() returns null and search falls back to vector similarity alone; recreate the table to enable it.