cognee-haystack package ships a memory store plus a writer and a retriever component, so you can store ChatMessages in cognee’s knowledge graph and feed relevant memories back into an Agent on every turn.
This integration is maintained by deepset in haystack-core-integrations and listed on the Haystack integrations page.
Why Use This Integration
- Native Haystack components:
CogneeWriterandCogneeRetrieverplug into anyPipelineand serialize with it - Two memory tiers: Write straight to the permanent knowledge graph, or to a cheap per-session cache that you promote later
- Natural language recall: Retrieve memories with any cognee search type (default
GRAPH_COMPLETION) as systemChatMessages - Per-user scoping: Pass a cognee user UUID as
user_idto scope writes and searches
Installation
haystack-ai>=2.24.0 and cognee>=1.0.9.
Quick Start
Set your keys (cognee extracts knowledge with an LLM; Haystack’sOpenAIChatGenerator reads OPENAI_API_KEY):
The components are synchronous. When called from inside a running event loop, cognee calls run on a shared background loop, so they also work in async applications and notebooks.
Components
Both components accept an optional
user_id (a cognee user UUID) at run time; omit it to use cognee’s default user.
Memory Store Options
CogneeMemoryStore(*, search_type="GRAPH_COMPLETION", top_k=5, dataset_name="haystack_memory", session_id=None, self_improvement=True, timeout=300)
The store also exposes
improve(session_id=None, user_id=None) and delete_all_memories(user_id=None).
Session Memory
By default, writes go straight to the permanent knowledge graph. Give a writer asession_id to write to that session’s lightweight cache instead, then promote the session into the graph with improve():
With a session-scoped store and a completion search type (such as the default
GRAPH_COMPLETION), cognee records each question and answer in the session cache as you search, so you don’t need a writer in the chat loop. delete_all_memories() forgets only the store’s dataset; the session cache survives. Use cognee.forget(everything=True) for a full wipe.How It Works
- Write:
CogneeWriterstores message text withcognee.remember, batched into one call on the permanent tier, or one entry per message on the session tier. Empty messages are skipped. - Retrieve:
CogneeRetrieverrunscognee.recallagainst the store’s dataset and wraps each result in a systemChatMessage - Inject: An
OutputAdapter(or any component you like) prepends the memories to the user’s messages before theAgentruns - Improve:
improve()runscognee.improveto enrich the graph and promote session content into it
GitHub Repository
View source code and examples
Examples
Runnable memory agent demo