Description
Adds IBM Db2 AI Vector Search as a fully supported vector store provider for Mem0 OSS. Db2 12.1.2+ ships a native VECTOR(n, FLOAT32) column type and VECTOR_DISTANCE function built into the engine — no extension, plugin, or sidecar process required. This means teams already running Db2 for their relational workloads can store and search memory embeddings in the same database, with no additional infrastructure.
Type of Change
Breaking Changes
N/A
What's included
Core implementation
mem0/vector_stores/db2.py — Db2VectorStore implementing the full VectorStoreBase interface:
| Method |
What it does |
insert |
Bulk inserts via executemany, hashes IDs to CHAR(16), stores vectors with VECTOR(CAST(? AS CLOB), dim, FLOAT32) and metadata as SYSTOOLS.JSON2BSON |
search |
VECTOR_DISTANCE nearest-neighbour search with optional metadata filters and FETCH FIRST n ROWS ONLY |
delete |
Accepts both raw string IDs and pre-hashed CHAR(16) IDs |
update |
Can update embedding only, metadata only, or both in one call |
get |
Single-row lookup by ID, returns None for missing records |
list |
Full scan with optional metadata filters and top_k limit, returns the [[OutputData]] shape Mem0 expects |
list_cols |
Queries SYSCAT.TABLES for all user tables in the current schema |
delete_col |
DROP TABLE (no-ops safely when table is absent) |
col_info |
Returns {schema, table_name, row_count} from SYSCAT.TABLES |
reset |
Drop + recreate — table is fully usable immediately after |
mem0/configs/vector_stores/db2.py — Pydantic Db2Config:
- Accepts either a pre-built
ibm_db_dbi.Connection via client or raw connection_params (database, host, port, username, password, optional security/ssl_cert for TLS)
- Validates and normalises
distance_strategy — supports EUCLIDEAN, COSINE, and DOT
- Configurable column names (
text_field, id_field, metadata_field, embedding_field) so it can be pointed at an existing table schema
- Rejects unknown extra fields
Distance to similarity score conversion
| Strategy |
Formula |
Range |
EUCLIDEAN |
1 / (1 + distance) |
(0, 1] |
COSINE |
max(0, 1 - distance) |
[0, 1] |
DOT |
returned as-is |
unbounded |
Metadata filtering
Filters run against the SYSTOOLS.BSON2JSON metadata column via JSON_VALUE. Supported filter shapes:
- Scalar equality —
{"user_id": "alice"}
- List / IN —
{"category": ["work", "personal"]}
- Wildcard existence —
{"run_id": "*"} (skipped in WHERE, matches any row)
- Multi-field AND — top-level keys are combined with
AND
Registration
mem0/vector_stores/configs.py — "db2" added to the provider registry so VectorStoreConfig(provider="db2", config={...}) and Memory.from_config({"vector_store": {"provider": "db2", ...}}) both work
pyproject.toml — ibm_db>=3.2.0 added to the vector-stores optional dependency group
Tests
tests/vector_stores/test_db2.py — 109 tests total:
- 93 unit tests — fully mocked (
ibm_db_dbi is stubbed via sys.modules when not installed), cover config validation, ID hashing, distance-to-score conversion, table creation, every CRUD method, NULL handling, filter SQL generation, and VectorStoreConfig provider registration
- 15 live integration tests — run against a real Db2 instance, guarded by a
@requires_db2_credentials skip marker, cover the full CRUD lifecycle plus test_live_documentation (end-to-end via Memory.from_config)
- Credentials loaded automatically from
examples/misc/.env via python-dotenv — no manual export needed
Documentation
docs/components/vectordbs/dbs/db2.mdx — new provider page with requirements, Memory.from_config usage example, full config table, score conversion explanation, and metadata filter examples
docs/docs.json — db2 added to the Supported Vector Databases navigation group
docs/llms.txt — Db2 entry added so the docs-llms-txt-check CI check stays green
Example
examples/misc/db2_vector_store_example.py — a self-contained runnable demo (no LLM needed) that walks through all 10 operations against a live Db2 instance: connect, insert, similarity search, filtered search, list with filter, get by ID, update, delete, collection info, and reset.
Test Coverage
Checklist
Description
Adds IBM Db2 AI Vector Search as a fully supported vector store provider for Mem0 OSS. Db2 12.1.2+ ships a native
VECTOR(n, FLOAT32)column type andVECTOR_DISTANCEfunction built into the engine — no extension, plugin, or sidecar process required. This means teams already running Db2 for their relational workloads can store and search memory embeddings in the same database, with no additional infrastructure.Type of Change
Breaking Changes
N/A
What's included
Core implementation
mem0/vector_stores/db2.py—Db2VectorStoreimplementing the fullVectorStoreBaseinterface:insertexecutemany, hashes IDs toCHAR(16), stores vectors withVECTOR(CAST(? AS CLOB), dim, FLOAT32)and metadata asSYSTOOLS.JSON2BSONsearchVECTOR_DISTANCEnearest-neighbour search with optional metadata filters andFETCH FIRST n ROWS ONLYdeleteCHAR(16)IDsupdategetNonefor missing recordslisttop_klimit, returns the[[OutputData]]shape Mem0 expectslist_colsSYSCAT.TABLESfor all user tables in the current schemadelete_colDROP TABLE(no-ops safely when table is absent)col_info{schema, table_name, row_count}fromSYSCAT.TABLESresetmem0/configs/vector_stores/db2.py— PydanticDb2Config:ibm_db_dbi.Connectionviaclientor rawconnection_params(database,host,port,username,password, optionalsecurity/ssl_certfor TLS)distance_strategy— supportsEUCLIDEAN,COSINE, andDOTtext_field,id_field,metadata_field,embedding_field) so it can be pointed at an existing table schemaDistance to similarity score conversion
EUCLIDEAN1 / (1 + distance)(0, 1]COSINEmax(0, 1 - distance)[0, 1]DOTMetadata filtering
Filters run against the
SYSTOOLS.BSON2JSONmetadata column viaJSON_VALUE. Supported filter shapes:{"user_id": "alice"}{"category": ["work", "personal"]}{"run_id": "*"}(skipped in WHERE, matches any row)ANDRegistration
mem0/vector_stores/configs.py—"db2"added to the provider registry soVectorStoreConfig(provider="db2", config={...})andMemory.from_config({"vector_store": {"provider": "db2", ...}})both workpyproject.toml—ibm_db>=3.2.0added to thevector-storesoptional dependency groupTests
tests/vector_stores/test_db2.py— 109 tests total:ibm_db_dbiis stubbed viasys.moduleswhen not installed), cover config validation, ID hashing, distance-to-score conversion, table creation, every CRUD method, NULL handling, filter SQL generation, andVectorStoreConfigprovider registration@requires_db2_credentialsskip marker, cover the full CRUD lifecycle plustest_live_documentation(end-to-end viaMemory.from_config)examples/misc/.envviapython-dotenv— no manualexportneededDocumentation
docs/components/vectordbs/dbs/db2.mdx— new provider page with requirements,Memory.from_configusage example, full config table, score conversion explanation, and metadata filter examplesdocs/docs.json—db2added to the Supported Vector Databases navigation groupdocs/llms.txt— Db2 entry added so thedocs-llms-txt-checkCI check stays greenExample
examples/misc/db2_vector_store_example.py— a self-contained runnable demo (no LLM needed) that walks through all 10 operations against a live Db2 instance: connect, insert, similarity search, filtered search, list with filter, get by ID, update, delete, collection info, and reset.Test Coverage
Checklist