---
title: "Vector Store Architecture"
description: "The vector store architecture provides a polymorphic data persistence and similarity retrieval layer that unifies disparate Cloud Vector Backends, Database Vector Stores, and Embedded Vector Stores..."
last_updated: "2026-10-11T17:37:10.218815+00:00"
canonical_url: "https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/vector-store-architecture"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [mem0/vector_stores/base.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py)
- [mem0-ts/src/oss/src/vector_stores/qdrant.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/qdrant.ts)
- [mem0/vector_stores/mongodb.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/mongodb.py)
- [mem0-ts/src/oss/src/vector_stores/neptune_analytics.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/neptune_analytics.ts)
- [mem0-ts/src/oss/src/vector_stores/databricks.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/databricks.ts)
- [mem0-ts/src/oss/src/vector_stores/s3_vectors.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/s3_vectors.ts)
- [mem0-ts/src/oss/src/vector_stores/milvus.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts)
- [mem0-ts/src/oss/src/vector_stores/memory.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/memory.ts)
- [mem0-ts/src/oss/src/vector_stores/base.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/base.ts)
- [mem0/vector_stores/weaviate.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/weaviate.py)
- [mem0/vector_stores/qdrant.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/qdrant.py)
- [mem0-ts/src/oss/src/vector_stores/opensearch.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/opensearch.ts)
- [mem0-ts/src/oss/src/vector_stores/mongodb.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/mongodb.ts)
- [mem0-ts/src/oss/src/vector_stores/pgvector.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/pgvector.ts)
- [mem0/vector_stores/neptune_analytics.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/neptune_analytics.py)
- [mem0-ts/src/oss/src/vector_stores/langchain.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/langchain.ts)
- [mem0-ts/src/oss/src/vector_stores/cassandra.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/cassandra.ts)
- [mem0-ts/src/oss/src/vector_stores/pinecone.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/pinecone.ts)
- [mem0/vector_stores/pgvector.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/pgvector.py)
- [mem0-ts/src/oss/src/vector_stores/weaviate.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/weaviate.ts)
- [mem0-ts/src/oss/src/vector_stores/redis.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/redis.ts)
- [mem0-ts/src/oss/src/vector_stores/elasticsearch.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/elasticsearch.ts)
- [mem0-ts/src/oss/src/vector_stores/azure_ai_search.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/azure_ai_search.ts)
- [mem0/vector_stores/azure_ai_search.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py)
- [mem0-ts/src/oss/src/vector_stores/turbopuffer.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/turbopuffer.ts)
- [mem0/vector_stores/langchain.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py)
- [mem0-ts/src/oss/src/vector_stores/upstash_vector.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/upstash_vector.ts)
- [mem0/vector_stores/opensearch.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/opensearch.py)
- [mem0/vector_stores/milvus.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/milvus.py)
- [mem0-ts/src/oss/src/utils/factory.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts)
</details>

## Overview

The vector store architecture provides a polymorphic data persistence and similarity retrieval layer that unifies disparate [Cloud Vector Backends](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/cloud-vector-backends), [Database Vector Stores](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/database-vector-stores), and [Embedded Vector Stores](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/embedded-vector-stores) under a shared abstract interface VectorStoreBase. By abstracting vector indexing, Approximate Nearest Neighbor (ANN) search, full-text keyword matching, and metadata filtering across engines such as Qdrant, Milvus, MongoDB, PostgreSQL, and LangChain, the system insulates higher-level memory management logic from vendor-specific driver idiosyncrasies and client query dialects.

Sources: [mem0/vector_stores/base.py:4-26](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L4-L26), [mem0-ts/src/oss/src/vector_stores/base.ts:3-33](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/base.ts#L3-L33), [mem0-ts/src/oss/src/utils/factory.ts:154-214](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L154-L214)

## Dual-runtime vector store contract abstractions

### Python Abstract Base Class Surface

The Python implementation defines `VectorStoreBase` as an abstract base class inheriting from `ABC`, establishing strict structural requirements across all concrete vector store implementations [mem0/vector_stores/base.py:1-4](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L1-L4). It enforces mandatory abstract methods for lifecycle operations, vector mutations, metadata storage, and collection management [mem0/vector_stores/base.py:5-67](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L5-L67).

Sources: [mem0/vector_stores/base.py:1-67](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L1-L67)

| Method | Parameters | Description | Sources |
| :--- | :--- | :--- | :--- |
| `create_col` | `name, vector_size, distance` | Create a new collection | [mem0/vector_stores/base.py:6-8](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L6-L8) |
| `insert` | `vectors, payloads=None, ids=None` | Insert vectors into a collection | [mem0/vector_stores/base.py:11-13](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L11-L13) |
| `search` | `query, vectors, top_k=5, filters=None` | Search for similar vectors | [mem0/vector_stores/base.py:16-26](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L16-L26) |
| `delete` | `vector_id` | Delete a vector by ID | [mem0/vector_stores/base.py:29-31](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L29-L31) |
| `update` | `vector_id, vector=None, payload=None` | Update a vector and its payload | [mem0/vector_stores/base.py:34-36](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L34-L36) |
| `get` | `vector_id` | Retrieve a vector by ID | [mem0/vector_stores/base.py:39-41](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L39-L41) |
| `list_cols` | None | List all collections | [mem0/vector_stores/base.py:44-46](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L44-L46) |
| `delete_col` | None | Delete a collection | [mem0/vector_stores/base.py:49-51](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L49-L51) |
| `col_info` | None | Get information about a collection | [mem0/vector_stores/base.py:54-56](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L54-L56) |
| `list` | `filters=None, top_k=None` | List all memories | [mem0/vector_stores/base.py:59-61](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L59-L61) |
| `reset` | None | Reset by deleting collection and recreating it | [mem0/vector_stores/base.py:64-66](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L64-L66) |

Sources: [mem0/vector_stores/base.py:5-66](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L5-L66)

> [!NOTE]
> All implementations must normalize search similarity scores to a higher-is-better range of `[0, 1]`. Distance metrics must be explicitly converted: Cosine distance uses `score = max(0.0, 1.0 - distance)`, L2 distance uses `score = 1.0 / (1.0 + distance)`, and inner product preserves raw values.
> Sources: [mem0/vector_stores/base.py:19-25](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L19-L25)

Base methods with default implementations provide optional capabilities: `keyword_search` executes BM25 full-text queries and returns `None` unless overridden, while `search_batch` processes multiple queries sequentially via `search` unless a provider supplies native batch execution [mem0/vector_stores/base.py:68-100](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L68-L100).

Sources: [mem0/vector_stores/base.py:68-100](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L68-L100)

### TypeScript Interface Contract

The TypeScript client SDK exposes an asynchronous `VectorStore` interface defining equivalent persistence and retrieval primitives mapped to Promise-based signatures [mem0-ts/src/oss/src/vector_stores/base.ts:3-33](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/base.ts#L3-L33).

```typescript
export interface VectorStore {
  insert(
    vectors: number[][],
    ids: string[],
    payloads: Record<string, any>[],
  ): Promise<void>;
  search(
    query: number[],
    topK?: number,
    filters?: SearchFilters,
  ): Promise<VectorStoreResult[]>;
  keywordSearch?(
    query: string,
    topK?: number,
    filters?: SearchFilters,
  ): Promise<VectorStoreResult[] | null>;
  get(vectorId: string): Promise<VectorStoreResult | null>;
  update(
    vectorId: string,
    vector: number[],
    payload: Record<string, any>,
  ): Promise<void>;
  delete(vectorId: string): Promise<void>;
  deleteCol(): Promise<void>;
  list(
    filters?: SearchFilters,
    topK?: number,
  ): Promise<[VectorStoreResult[], number]>;
  getUserId(): Promise<string>;
  setUserId(userId: string): Promise<void>;
  initialize(): Promise<void>;
```
Sources: [mem0-ts/src/oss/src/vector_stores/base.ts:3-33](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/base.ts#L3-L33)

> [!IMPORTANT]
> The TypeScript contract models optional capabilities through optional interface members (`keywordSearch?`), whereas the Python runtime relies on base class method defaults returning `None`.
> Sources: [mem0/vector_stores/base.py:68-83](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L68-L83), [mem0-ts/src/oss/src/vector_stores/base.ts:14-18](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/base.ts#L14-L18)

## Factory instantiation and runtime resolution

### VectorStoreFactory Provider Mapping

The `VectorStoreFactory` class resolves runtime configuration strings into concrete vector store instances via a case-insensitive `switch` statement over the provider identifier [mem0-ts/src/oss/src/utils/factory.ts:154-214](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L154-L214).

Sources: [mem0-ts/src/oss/src/utils/factory.ts:154-214](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L154-L214)

| Provider Identifier(s) | Concrete Class | Sources |
| :--- | :--- | :--- |
| `memory` | `MemoryVectorStore` | [mem0-ts/src/oss/src/utils/factory.ts:157-158](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L157-L158) |
| `baidu` | `BaiduDB` | [mem0-ts/src/oss/src/utils/factory.ts:159-160](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L159-L160) |
| `qdrant` | `Qdrant` | [mem0-ts/src/oss/src/utils/factory.ts:161-162](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L161-L162) |
| `chroma` | `ChromaDB` | [mem0-ts/src/oss/src/utils/factory.ts:163-164](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L163-L164) |
| `redis` | `RedisDB` | [mem0-ts/src/oss/src/utils/factory.ts:165-166](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L165-L166) |
| `valkey` | `ValkeyDB` | [mem0-ts/src/oss/src/utils/factory.ts:167-168](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L167-L168) |
| `supabase` | `SupabaseDB` | [mem0-ts/src/oss/src/utils/factory.ts:169-170](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L169-L170) |
| `langchain` | `LangchainVectorStore` | [mem0-ts/src/oss/src/utils/factory.ts:171-172](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L171-L172) |
| `vectorize` | `VectorizeDB` | [mem0-ts/src/oss/src/utils/factory.ts:173-174](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L173-L174) |
| `azure-ai-search` | `AzureAISearch` | [mem0-ts/src/oss/src/utils/factory.ts:175-176](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L175-L176) |
| `vertex_ai_vector_search` | `VertexAIVectorSearch` | [mem0-ts/src/oss/src/utils/factory.ts:177-178](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L177-L178) |
| `pgvector` | `PGVector` | [mem0-ts/src/oss/src/utils/factory.ts:179-180](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L179-L180) |
| `databricks` | `DatabricksVectorStore` | [mem0-ts/src/oss/src/utils/factory.ts:181-182](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L181-L182) |
| `neptune`, `neptune-analytics` | `NeptuneAnalyticsVectorStore` | [mem0-ts/src/oss/src/utils/factory.ts:183-185](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L183-L185) |
| `elasticsearch` | `ElasticsearchDB` | [mem0-ts/src/oss/src/utils/factory.ts:186-187](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L186-L187) |
| `opensearch` | `OpenSearchDB` | [mem0-ts/src/oss/src/utils/factory.ts:188-189](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L188-L189) |
| `upstash_vector` | `UpstashVector` | [mem0-ts/src/oss/src/utils/factory.ts:190-191](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L190-L191) |
| `azure_mysql` | `AzureMySQLDB` | [mem0-ts/src/oss/src/utils/factory.ts:192-193](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L192-L193) |
| `cassandra` | `CassandraDB` | [mem0-ts/src/oss/src/utils/factory.ts:194-195](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L194-L195) |
| `pinecone` | `PineconeDB` | [mem0-ts/src/oss/src/utils/factory.ts:196-197](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L196-L197) |
| `s3-vectors`, `s3_vectors` | `S3Vectors` | [mem0-ts/src/oss/src/utils/factory.ts:198-200](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L198-L200) |
| `turbopuffer` | `TurbopufferDB` | [mem0-ts/src/oss/src/utils/factory.ts:201-202](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L201-L202) |
| `milvus` | `Milvus` | [mem0-ts/src/oss/src/utils/factory.ts:203-204](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L203-L204) |
| `mongodb` | `MongoDB` | [mem0-ts/src/oss/src/utils/factory.ts:205-206](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L205-L206) |
| `weaviate` | `WeaviateDB` | [mem0-ts/src/oss/src/utils/factory.ts:207-208](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L207-L208) |
| `oracledb` | `OracleAIVectorSearch` | [mem0-ts/src/oss/src/utils/factory.ts:209-210](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L209-L210) |

Sources: [mem0-ts/src/oss/src/utils/factory.ts:154-214](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L154-L214)

> [!WARNING]
> Provider matching normalizes input keys via `provider.toLowerCase()` but throws an explicit runtime `Error` containing `Unsupported vector store provider: ${provider}` if no matching case or alias is found.
> Sources: [mem0-ts/src/oss/src/utils/factory.ts:155-213](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/utils/factory.ts#L155-L213)

## Normalized payload and result structures

### Document Schema and Payload Serialization

The document representation layer standardizes how vector entries map to backend fields [mem0/vector_stores/azure_ai_search.py:164-170](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L164-L170). In backends such as `AzureAISearch`, metadata payloads are serialized into JSON strings alongside explicit filterable dimensions like `user_id`, `run_id`, and `agent_id` extracted directly from the payload dictionary [mem0/vector_stores/azure_ai_search.py:137-147](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L137-L147), [mem0/vector_stores/azure_ai_search.py:164-170](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L164-L170).

Sources: [mem0/vector_stores/azure_ai_search.py:137-170](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L137-L170)

```python
class OutputData(BaseModel):
    id: Optional[str]
    score: Optional[float]
    payload: Optional[dict]

```
Sources: [mem0/vector_stores/azure_ai_search.py:37-41](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L37-L41)

> [!NOTE]
> `OutputData` models represent query hits across backends, standardizing fields into nullable `id`, `score`, and `payload` attributes [mem0/vector_stores/azure_ai_search.py:37-41](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L37-L41).
> Sources: [mem0/vector_stores/azure_ai_search.py:37-41](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L37-L41)

### Distance-to-Similarity Conversion Rules

All Python implementations of `VectorStoreBase` must return normalized similarity scores within the range `[0, 1]`, where higher values indicate greater similarity [mem0/vector_stores/base.py:19-20](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L19-L20). When a backend natively uses distance metrics, the score must be converted according to explicit mathematical transformations before returning [mem0/vector_stores/base.py:21-25](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L21-L25).

Sources: [mem0/vector_stores/base.py:19-25](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L19-L25)

| Metric Type | Conversion Formula / Rule | Score Range / Behavior |
| :--- | :--- | :--- |
| **Cosine distance** | `score = max(0.0, 1.0 - distance)` | Clamped between `0.0` and `1.0` |
| **L2 distance** | `score = 1.0 / (1.0 + distance)` | Inverted scale, higher is closer |
| **Inner product** | `score = value` | Preserved directly as higher is better |

Sources: [mem0/vector_stores/base.py:21-25](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/base.py#L21-L25)

## Query filter DSL translation strategies

### Filter Expression Generation

Vector store backends translate incoming `SearchFilters` dictionaries into native query language expressions [mem0-ts/src/oss/src/vector_stores/milvus.ts:245-259](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L245-L259), [mem0/vector_stores/azure_ai_search.py:195-213](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L195-L213). In the TypeScript `Milvus` provider, metadata keys are assembled into string literal comparisons formatted as `(metadata["${key}"] == "${escaped}")` for strings, or `(metadata["${key}"] == ${value})` for numbers and booleans, joined by ` and ` [mem0-ts/src/oss/src/vector_stores/milvus.ts:248-258](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L248-L258). 

Sources: [mem0-ts/src/oss/src/vector_stores/milvus.ts:245-259](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L245-L259)

```typescript
    if (typeof value === "string") {
      // Escape backslashes before quotes so a value can't break out of the
      // string literal (order matters, exactly as in the Python provider).
      const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
      operands.push(`(metadata["${key}"] == "${escaped}")`);
    } else if (typeof value === "number" || typeof value === "boolean") {
      operands.push(`(metadata["${key}"] == ${value})`);
    } else {
      throw new Error(
        `Filter value for ${JSON.stringify(key)} must be a string, number, or boolean, got ${typeof value}`,
      );
    }
  }
  return operands.length > 0 ? operands.join(" and ") : undefined;
}
```
Sources: [mem0-ts/src/oss/src/vector_stores/milvus.ts:245-259](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L245-L259)

Similarly, the Python `AzureAISearch` vector store translates filter keys by sanitizing identifiers and evaluating data types to construct OData filter expressions [mem0/vector_stores/azure_ai_search.py:192-213](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L192-L213). String values have single quotes escaped as `''`, booleans are converted via lowercase string representation, and numbers are appended directly before being joined with ` and ` [mem0/vector_stores/azure_ai_search.py:199-212](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L199-L212).

Sources: [mem0/vector_stores/azure_ai_search.py:192-213](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L192-L213)

```python
def _build_filter_expression(self, filters):
    filter_conditions = []
    for key, value in filters.items():
        safe_key = self._sanitize_key(key)
        if isinstance(value, str):
            safe_value = value.replace("'", "''")
            condition = f"{safe_key} eq '{safe_value}'"
        elif isinstance(value, bool):
            condition = f"{safe_key} eq {str(value).lower()}"
        elif isinstance(value, (int, float)):
            condition = f"{safe_key} eq {value}"
        else:
            raise ValueError(
                f"Filter value for {key!r} must be str, int, float, or bool, "
                f"got {type(value).__name__}"
            )
        filter_conditions.append(condition)
    filter_expression = " and ".join(filter_conditions)
    return filter_expression
```
Sources: [mem0/vector_stores/azure_ai_search.py:195-213](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L195-L213)

### Filter Translation Mapping

| Backend Provider | String Format | Boolean Format | Number Format | Operator Join |
| :--- | :--- | :--- | :--- | :--- |
| **Milvus** (TypeScript) | `(metadata["key"] == "escaped")` | `(metadata["key"] == true)` | `(metadata["key"] == 123)` | ` and ` |
| **Azure AI Search** (Python) | `key eq 'value'` | `key eq true` | `key eq 123` | ` and ` |

Sources: [mem0-ts/src/oss/src/vector_stores/milvus.ts:245-259](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L245-L259), [mem0/vector_stores/azure_ai_search.py:195-213](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L195-L213)

> [!WARNING]
> Filter value translation logic strictly validates input types; unsupported types trigger an explicit runtime `Error` in Milvus or a `ValueError` in Azure AI Search if values do not match allowed primitives.
> Sources: [mem0-ts/src/oss/src/vector_stores/milvus.ts:253-256](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L253-L256), [mem0/vector_stores/azure_ai_search.py:207-210](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/azure_ai_search.py#L207-L210)

## LangChain bridge and adapter architecture

### Client Validation and Embedding Fallbacks

The LangChain bridge allows external vector stores to integrate with both runtimes. In TypeScript, `LangchainVectorStore` validates that a provided client object implements `addVectors` and `similaritySearchVectorWithScore` [mem0-ts/src/oss/src/vector_stores/langchain.ts:16-30](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/langchain.ts#L16-L30). In Python, the `Langchain` class inspects the client interface to check for `add_embeddings`; if absent, it falls back to calling `add_texts` using data extracted from payloads [mem0/vector_stores/langchain.py:95-103](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L95-L103).

Sources: [mem0-ts/src/oss/src/vector_stores/langchain.ts:16-30](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/langchain.ts#L16-L30), [mem0/vector_stores/langchain.py:95-103](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L95-L103)

```typescript
constructor(config: LangchainStoreConfig) {
  if (!config.client || typeof config.client !== "object") {
    throw new Error(
      "Langchain vector store provider requires an initialized Langchain VectorStore instance passed via the 'client' field.",
    );
  }
  // Basic checks for core methods
  if (
    typeof config.client.addVectors !== "function" ||
    typeof config.client.similaritySearchVectorWithScore !== "function"
  ) {
    throw new Error(
      "Provided Langchain 'client' does not appear to be a valid Langchain VectorStore (missing addVectors or similaritySearchVectorWithScore method).",
    );
  }
```
Sources: [mem0-ts/src/oss/src/vector_stores/langchain.ts:16-30](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/langchain.ts#L16-L30)

> [!WARNING]
> Initializing `LangchainVectorStore` in TypeScript throws an explicit `Error` if `config.client` is missing or omits required methods like `addVectors` or `similaritySearchVectorWithScore`.
> Sources: [mem0-ts/src/oss/src/vector_stores/langchain.ts:17-30](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/langchain.ts#L17-L30)

### Scored Search Method Resolution

The Python adapter iterates through a ranked priority list of methods to retrieve document-score pairs from diverse underlying stores [mem0/vector_stores/langchain.py:27-31](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L27-L31), [mem0/vector_stores/langchain.py:114-129](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L114-L129).

Sources: [mem0/vector_stores/langchain.py:27-31](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L27-L31), [mem0/vector_stores/langchain.py:114-129](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L114-L129)

| Method Name | Target Store Implementation |
| :--- | :--- |
| `similarity_search_by_vector_with_relevance_scores` | Chroma |
| `similarity_search_with_score_by_vector` | FAISS, Qdrant |
| `similarity_search_by_vector_with_score` | Pinecone, YDB |

Sources: [mem0/vector_stores/langchain.py:27-31](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L27-L31), [mem0/vector_stores/langchain.py:114-129](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L114-L129)

> [!NOTE]
> If none of the scored vector methods are found on the LangChain client instance, search execution falls back to `similarity_search_by_vector`, assigning a default score of `1.0` so subsequent rankers do not receive `None`.
> Sources: [mem0/vector_stores/langchain.py:131-141](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/vector_stores/langchain.py#L131-L141)

## Input sanitization and injection prevention

### Identifier and Payload Escaping Mechanics

Vector backends that expose query languages or dynamic shell interfaces implement strict regex validations and string escaping routines to prevent injection attacks. In Databricks, identifiers are validated against `SAFE_IDENTIFIER_RE` (`/^[A-Za-z_][A-Za-z0-9_]{0,127}$/`), and SQL values are serialized with backslashes and single quotes escaped prior to literal interpolation [mem0-ts/src/oss/src/vector_stores/databricks.ts:5-154](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/databricks.ts#L5-L154). Similarly, Milvus escapes backslashes and double quotes when constructing string filter operands [mem0-ts/src/oss/src/vector_stores/milvus.ts:245-249](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L245-L249).

Sources: [mem0-ts/src/oss/src/vector_stores/databricks.ts:5-154](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/databricks.ts#L5-L154), [mem0-ts/src/oss/src/vector_stores/milvus.ts:245-249](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/milvus.ts#L245-L249)

```typescript
const SAFE_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
const DEFAULT_PAGE_SIZE = 100;
const MAX_QUERY_RESULTS = 10_000;
const MAX_FULL_TEXT_RESULTS = 200;
const DEFAULT_SYNC_POLL_INTERVAL_MS = 1000;
const DEFAULT_SYNC_TIMEOUT_MS = 5 * 60 * 1000;
```
Sources: [mem0-ts/src/oss/src/vector_stores/databricks.ts:5-10](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/databricks.ts#L5-L10)

> [!CAUTION]
> Databricks string serialization handles backslashes before doubling quotes so that literal escape characters do not prematurely close SQL string boundaries or corrupt round-trip data.
> Sources: [mem0-ts/src/oss/src/vector_stores/databricks.ts:149-154](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/databricks.ts#L149-L154)

### Filter Key Sanitization and Type Enforcement

Query filter keys and values undergo rigorous validation across search integrations to reject malformed payloads before execution. Elasticsearch evaluates filter keys against `SAFE_FILTER_KEY` (`/^[a-zA-Z_][a-zA-Z0-9_]*$/`) and verifies that scalar values are restricted to strings, numbers, or booleans [mem0-ts/src/oss/src/vector_stores/elasticsearch.ts:26-44](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/elasticsearch.ts#L26-L44). Redis tag filters explicitly escape special characters including `-`, `|`, and whitespace to prevent RediSearch operator injection [mem0-ts/src/oss/src/vector_stores/redis.ts:13-24](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/redis.ts#L13-L24).

Sources: [mem0-ts/src/oss/src/vector_stores/elasticsearch.ts:26-44](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/elasticsearch.ts#L26-L44), [mem0-ts/src/oss/src/vector_stores/redis.ts:13-24](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/redis.ts#L13-L24)

```typescript
const SAFE_FILTER_KEY = /^[a-zA-Z_][a-zA-Z0-9_]*$/;

// Mirrors the Python provider's _validate_filter. Filter keys are interpolated
// into `metadata.${key}` field paths, so reject anything that is not a plain
// identifier and reject non-scalar values before they reach the query.
function validateFilter(key: string, value: unknown): void {
  if (typeof key !== "string" || !SAFE_FILTER_KEY.test(key)) {
    throw new Error(`Invalid filter key: ${JSON.stringify(key)}`);
  }
```
Sources: [mem0-ts/src/oss/src/vector_stores/elasticsearch.ts:26-34](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/elasticsearch.ts#L26-L34)

> [!WARNING]
> Unescaped hyphens or punctuation in Redis filter tag values cause RediSearch to interpret them as boolean operators or trigger immediate query syntax validation failures.
> Sources: [mem0-ts/src/oss/src/vector_stores/redis.ts:13-18](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/vector_stores/redis

## Related

- [Cloud Vector Backends](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/cloud-vector-backends)
- [Database Vector Stores](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/database-vector-stores)
- [Embedded Vector Stores](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/embedded-vector-stores)


## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/llms.txt) for all pages in this wiki.
