langchain-yantrikdb
A vector store treats your agent's memory as an append-only pile. Store "the rate limit is 100/min" today and "the rate limit is 500/min" next month, and both sit there forever, equally weighted — retrieval returns whichever embeds closer to the query, and nothing ever notices they disagree.
This package plugs YantrikDB — a
cognitive memory engine — into LangChain's standard interfaces. Same
VectorStore API your chains already use, but stored records behave like
memories:
- Temporal decay — each record has a half-life; ranking blends similarity with decay, recency, and importance, so stale facts lose to fresh ones at equal similarity.
- Contradiction detection —
store.think()scans what you stored and flags records that disagree, with rids and a suggested action. - Consolidation — near-duplicates get merged instead of accumulating.
- Explainable retrieval — every hit can tell you why it surfaced
(
"semantically similar (0.90)","recent","important (decay=0.80)").
No external services and no model download: the engine is an embedded
Rust core (SQLite-backed, single file) with a bundled 64-dimension
embedder. Bring your own LangChain Embeddings if you want a larger
model.
60 seconds
pip install langchain-yantrikdb
from langchain_yantrikdb import YantrikDBVectorStore
store = YantrikDBVectorStore(db_path="./memory.db")
store.add_texts([
"The deploy target is eu-west-1",
"The database is PostgreSQL 16",
])
docs = store.similarity_search("where do we deploy?", k=1)
print(docs[0].page_content) # The deploy target is eu-west-1
retriever = store.as_retriever() # drop into any chain
The part a plain vector store can't do
Store two facts that contradict each other, then ask the engine to think:
store.add_texts([
"The API rate limit is 100 requests per minute",
"The API rate limit is 500 requests per minute",
])
report = store.think()
for trigger in report["triggers"]:
print(trigger["reason"])
# Two memories are 97% similar and may be redundant (rid_a=..., rid_b=...):
# 'The API rate limit is 500 requests per minute' vs
# 'The API rate limit is 100 requests per minute'
# suggested_action: consolidate_or_forget
And ask retrieval to explain itself:
for doc, why in store.explain_search("what is the rate limit?", k=2):
print(doc.page_content, why["why_retrieved"])
# ... ['semantically similar (0.93)', 'recent', 'important (decay=0.80)']
Scores returned by similarity_search_with_score are the same blended
score the engine ranks by (similarity x decay x recency x importance,
in [0, 1]) — documented, not raw cosine in disguise.
Chat history
YantrikDBChatMessageHistory persists sessions in the same database
file, one namespace per session. Tool calls and additional_kwargs
survive the round trip.
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_yantrikdb import YantrikDBChatMessageHistory
chain_with_history = RunnableWithMessageHistory(
chain,
lambda session_id: YantrikDBChatMessageHistory(
session_id, db_path="./memory.db"
),
input_messages_key="input",
history_messages_key="history",
)
The buffer keeps the most recent 1,000 messages per session (configurable
via max_turns). For the long-term layer — the one that decays,
consolidates, and gets contradiction-checked — distill what matters into
a YantrikDBVectorStore on the same file.
Your own embeddings
from langchain_openai import OpenAIEmbeddings
store = YantrikDBVectorStore(
db_path="./memory.db",
embedding=OpenAIEmbeddings(model="text-embedding-3-small"),
namespace="docs",
)
The embedding dimension is probed at construction and must stay
consistent for the lifetime of the database file. With embedding=None
the bundled embedder is used — adequate for agent-memory recall, smaller
than sentence-transformer models.
When NOT to use this
- Static document RAG at scale. If the corpus doesn't change and you just need nearest-neighbour over a million chunks, a dedicated vector database is the better tool. YantrikDB's decay and consolidation add nothing to documents that never go stale.
- You need caller-supplied ids. YantrikDB assigns UUIDv7 rids;
add_texts(ids=...)raises. LangChain's indexing API that depends on stable external ids won't work with this store. - MMR retrieval.
max_marginal_relevance_searchis not implemented. - Exact score reproducibility. Blended scores move as records age — that is the point, but it breaks tests that pin exact score values.
Interface coverage
| LangChain surface | Status |
|---|---|
add_texts / add_documents |
supported (engine-assigned ids) |
similarity_search / _with_score / _by_vector |
supported |
similarity_search_with_relevance_scores |
supported (scores already in [0, 1]) |
delete(ids) / delete() (namespace-wide) |
supported (tombstone) |
get_by_ids |
supported |
from_texts |
supported |
as_retriever |
supported |
| async variants | inherited executor-backed defaults |
max_marginal_relevance_search |
not implemented |
BaseChatMessageHistory |
supported, per-session namespaces |
Extras beyond the standard interface: explain_search(), think(),
conflicts(), and store.db for the full engine API (record links,
knowledge graph, memory packs).
Tested against langchain-core 0.3.x and 1.x on Python 3.10-3.14.
Related projects
- yantrikdb — the engine itself: Rust core, Python bindings, CLI, REST server.
- yantrikdb-mcp — the same memory as an MCP server for Claude Code, Cursor, and other MCP hosts.
- yantrikdb-hermes-plugin — memory provider for hermes-agent.
License
MIT (this integration). The YantrikDB engine is AGPL-3.0.
Pranab Sarkar, Independent Researcher
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_yantrikdb-0.1.0.tar.gz.
File metadata
- Download URL: langchain_yantrikdb-0.1.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
200790f4ec9702d9f4973fa4bff01b957c2dc62d108b171bc8513747facd90d2
|
|
| MD5 |
a2da14b87d35c3c55c4c0a004bc103be
|
|
| BLAKE2b-256 |
b8c8fc93f36f7ee80f006522f95ad9a9008bed7378cc55cf0150fb4adf2fb148
|
Provenance
The following attestation bundles were made for langchain_yantrikdb-0.1.0.tar.gz:
Publisher:
publish.yml on yantrikos/langchain-yantrikdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_yantrikdb-0.1.0.tar.gz -
Subject digest:
200790f4ec9702d9f4973fa4bff01b957c2dc62d108b171bc8513747facd90d2 - Sigstore transparency entry: 2409501628
- Sigstore integration time:
-
Permalink:
yantrikos/langchain-yantrikdb@21df94e6a357a20e83429ad0e2b935d9ef5f20b2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/yantrikos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21df94e6a357a20e83429ad0e2b935d9ef5f20b2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_yantrikdb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_yantrikdb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
913a8c55d8c882d4d22fb4e70d9f25431e983fbb3d602bfb4a0a2e6d6ae0c907
|
|
| MD5 |
3ff77b16b636d37e429db706e221d5a1
|
|
| BLAKE2b-256 |
4eb1d7d07fdd7642c266acf55e14f7a21fc55685d3e1e720364812ff2e39388e
|
Provenance
The following attestation bundles were made for langchain_yantrikdb-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on yantrikos/langchain-yantrikdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_yantrikdb-0.1.0-py3-none-any.whl -
Subject digest:
913a8c55d8c882d4d22fb4e70d9f25431e983fbb3d602bfb4a0a2e6d6ae0c907 - Sigstore transparency entry: 2409501903
- Sigstore integration time:
-
Permalink:
yantrikos/langchain-yantrikdb@21df94e6a357a20e83429ad0e2b935d9ef5f20b2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/yantrikos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21df94e6a357a20e83429ad0e2b935d9ef5f20b2 -
Trigger Event:
release
-
Statement type: