Skip to main content

LangChain & LangGraph

langchain-rushdb (Python) and @rushdb/langchain (TypeScript) plug RushDB into LangChain and LangGraph:

ComponentInterfaceUse it for
RushDBVectorStoreLangChain VectorStoreRAG over documents with filterable metadata, applied before ranking
RushDBHybridRetrieverLangChain retrieverVector + BM25 keyword search fused in the engine (RRF or DBSF)
RushDBStoreLangGraph BaseStoreLong-term agent memory: namespaces, filters, semantic search, TTL
RushDBSaverLangGraph BaseCheckpointSaverThread state: resume after interrupts, human-in-the-loop, time travel

All four work on RushDB Cloud and on a self-hosted RushDB engine with the same code. Only the client you pass in differs.

Install​

pip install langchain-rushdb

Connect​

Every class takes a RushDB SDK client. When you omit it, the client is built from the environment.

import os

from rushdb import RushDB

client = RushDB(os.environ["RUSHDB_API_KEY"]) # RushDB Cloud
# client = RushDB(os.environ["RUSHDB_ENGINE_TOKEN"], direct=True, engine_url="http://127.0.0.1:3000")
ModeEnvironment variables
RushDB CloudRUSHDB_API_KEY, optional RUSHDB_URL
Self-hosted engineRUSHDB_ENGINE_URL, RUSHDB_ENGINE_TOKEN, optional RUSHDB_SCOPE on a multitenant engine

Setting both groups is an error, so a deployment never picks a mode by accident.

Vector Store and Hybrid Retrieval​

from langchain_openai import OpenAIEmbeddings
from langchain_rushdb import RushDBHybridRetriever, RushDBVectorStore

store = RushDBVectorStore(
OpenAIEmbeddings(model="text-embedding-3-small"),
client=client,
hybrid=True, # also keep a BM25 text index
)
store.add_texts(
["RushDB stores JSON as a graph", "LangGraph persists agent state"],
metadatas=[{"topic": "db", "year": 2026}, {"topic": "agents", "year": 2025}],
)

store.similarity_search("graph database", k=2, filter={"year": {"$gte": 2026}})

retriever = RushDBHybridRetriever(vectorstore=store, k=5, fusion="rrf")
retriever.invoke("how are agent checkpoints stored?")

Each document is one record (label LC_DOCUMENT by default). It holds the text, the full metadata, and the metadata's top-level values as filterable properties. Filters use the LangChain form:

OperatorsNotes
equality, $eq, $ne, $in, $ninstrings, numbers, booleans
$gt, $gte, $lt, $ltenumbers and ISO-8601 datetimes
$exists, $contains, $startsWith, $endsWith
$and, $or, $not

An unsupported filter raises an error; it is never ignored. To use the full where syntax, including conditions on related records, pass a raw RushDB filter as where.

The hybrid retriever uses the engine's hybrid search: the filter is applied first, then the vector and keyword rankings are fused.

Long-Term Memory Store​

from langchain_rushdb import RushDBStore

store = RushDBStore(
client=client,
index={"dims": 1536, "embed": "openai:text-embedding-3-small", "fields": ["text"]},
ttl={"default_ttl": 60 * 24 * 30}, # minutes
)
store.put(("users", "u1", "memories"), "m1", {"text": "Prefers dark mode", "kind": "pref"})
store.search(("users", "u1"), query="ui preferences", filter={"kind": "pref"})

graph = builder.compile(store=store)

RushDB records have no native expiry. Expired items are hidden from every read, and sweep() deletes them. Start the sweeper to run sweep() periodically. In TypeScript, the TTL is set per store (ttl: { defaultTtl }, in minutes), because LangGraph.js's put takes no TTL.

Checkpointer​

from langchain_rushdb import RushDBSaver

graph = builder.compile(checkpointer=RushDBSaver(client=client))
graph.invoke(inputs, {"configurable": {"thread_id": "t-1"}})

Each checkpoint write is one RushDB transaction, so a graph can resume from a different process or machine. A checkpoint is read back by the language that wrote it, because LangGraph's Python and JavaScript serializers differ. Both packages share the record layout, so either one can list and delete any thread.

Cloud and Self-Hosted​

RushDB CloudSelf-hosted
Vector store, hybrid retriever✓✓
Memory store, checkpointer✓✓
Your own LangChain Embeddings✓✓
RushDB-managed embeddings ("managed")✓—

A self-hosted engine never computes embeddings. Passing "managed" instead of an Embeddings object works only on RushDB Cloud, and raises an error against a self-hosted engine.

Data Layout​

The connector writes ordinary records, so you can inspect and query them in the dashboard, with SearchQuery or with SQL. The labels and properties are specified in the repository's record layout.

Next Steps​