Azure Cosmos DB-backed store with optional vector search.
Provides LangGraph long-term memory persistence using Azure Cosmos DB.
Example:
Basic setup and usage::
from langchain_azure_cosmosdb import CosmosDBStore
store = CosmosDBStore.from_conn_string(
conn_string="AccountEndpoint=https://...;AccountKey=...",
database_name="langgraph",
container_name="store",
)
store.setup()
store.put(("users", "123"), "prefs", {"theme": "dark"})
item = store.get(("users", "123"), "prefs")
Vector search using LangChain embeddings::
from langchain.embeddings import init_embeddings
from langchain_azure_cosmosdb import CosmosDBStore
store = CosmosDBStore.from_conn_string(
conn_string="...",
database_name="langgraph",
container_name="store",
index={
"dims": 1536,
"embed": init_embeddings("openai:text-embedding-3-small"),
"fields": ["text"],
},
)
store.setup()
store.put(("docs",), "doc1", {"text": "Python tutorial"})
results = store.search(("docs",), query="programming guides", limit=2)
Note:
Semantic search is disabled by default. Provide an index
configuration when creating the store to enable it.
Warning:
Make sure to call setup() before first use to create the
database and container.