InMemoryStore(
self,
*,
index: IndexConfig | None = None,
)| Name | Type |
|---|---|
| index | IndexConfig | None |
In-memory dictionary-backed store with optional vector search.
Basic key-value storage: store = InMemoryStore() store.put(("users", "123"), "prefs", {"theme": "dark"}) item = store.get(("users", "123"), "prefs")
Vector search with embeddings: from langchain.embeddings import init_embeddings store = InMemoryStore(index={ "dims": 1536, "embed": init_embeddings("openai:text-embedding-3-small"), "fields": ["text"], })
# Store documents
store.put(("docs",), "doc1", {"text": "Python tutorial"})
store.put(("docs",), "doc2", {"text": "TypeScript guide"})
# Search by similarity
results = store.search(("docs",), query="python programming")
Note:
Semantic search is disabled by default. You can enable it by providing an index configuration
when creating the store. Without this configuration, all index arguments passed to
put or aputwill have no effect.
Warning:
This store keeps all data in memory. Data is lost when the process exits. For persistence, use a database-backed store like PostgresStore.
Tip:
For vector search, install numpy for better performance:
pip install numpy