Production-oriented LanceDB adapter for MGP.
This adapter maps canonical MGP memory objects onto a local or self-managed LanceDB table.
It is intended to show how a vector database backend can support:
- persistent governed memory storage
- semantic recall over canonical memory objects
- optional hybrid recall through LanceDB full-text search
- soft delete and hard purge while preserving MGP lifecycle semantics
- self-hosted deployment paths that do not depend on a managed memory vendor
- Python environment with
lancedbinstalled - a writable database directory in
MGP_LANCEDB_DIRor--lancedb-dir - an embedding provider configuration
The adapter can use:
fakefor deterministic offline testingopenaiopenroutervia the OpenAI-compatible API surfacegemini-text- any other provider exposed through the LanceDB embedding registry
Recommended environment variables:
MGP_LANCEDB_EMBEDDING_PROVIDERMGP_LANCEDB_EMBEDDING_MODELMGP_LANCEDB_EMBEDDING_API_KEYMGP_LANCEDB_EMBEDDING_BASE_URLMGP_LANCEDB_EMBEDDING_DIMfor thefakeprovider
OpenRouter example:
export MGP_ADAPTER=lancedb
export MGP_LANCEDB_DIR=./data/lancedb
export MGP_LANCEDB_TABLE=memories
export MGP_LANCEDB_ENABLE_HYBRID=1
export MGP_LANCEDB_EMBEDDING_PROVIDER=openrouter
export MGP_LANCEDB_EMBEDDING_MODEL=openai/text-embedding-3-small
export MGP_LANCEDB_EMBEDDING_API_KEY=...
export MGP_LANCEDB_EMBEDDING_BASE_URL=https://openrouter.ai/api/v1Offline test example:
export MGP_ADAPTER=lancedb
export MGP_LANCEDB_DIR=./data/lancedb
export MGP_LANCEDB_EMBEDDING_PROVIDER=fake
export MGP_LANCEDB_EMBEDDING_MODEL=mgp-fake-embedding-v1The adapter stores each memory as one LanceDB row with:
- normalized lookup fields such as subject, scope, type, and state
search_textandconsumable_textfor retrieval and prompt-safe consumption- a
vectorcolumn for semantic recall memory_jsoncontaining the full canonical MGP memory object
This preserves unknown extensions across round trips while still giving the adapter efficient filter columns.
backend_ref.adapteris alwayslancedbbackend_ref.mgp_stateis one ofactive,expired,revoked, ordeleted- the full canonical MGP object is restored from
memory_json - hybrid search uses LanceDB FTS plus vector search when enabled
- delete is a soft-delete implemented by state transition
- purge is a hard delete implemented by removing the LanceDB row
- search modes are
semantic, orsemantic+hybridwhen FTS setup succeeds - prompt-safe views are still produced at the gateway policy layer
- TTL is adapter-managed and policy-enforced, not a LanceDB native expiration feature
- conflict detection, merge, and write-time dedupe remain gateway-level behaviors
For a deterministic local run:
export MGP_ADAPTER=lancedb
export MGP_LANCEDB_DIR=./data/lancedb
export MGP_LANCEDB_EMBEDDING_PROVIDER=fake
export MGP_LANCEDB_EMBEDDING_MODEL=mgp-fake-embedding-v1
make testOr run the suite directly:
MGP_ADAPTER=lancedb ./.venv/bin/python -m pytest compliance- graph-native relationship retrieval is not supported
- TTL is adapter-managed rather than native to LanceDB
- hybrid search depends on LanceDB FTS support and may fall back to semantic-only mode
- changing the embedding model or vector dimension for an existing non-empty table is treated as a configuration error