Skip to main content
Give your Haystack agents and pipelines persistent memory powered by cognee. The 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: CogneeWriter and CogneeRetriever plug into any Pipeline and 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 system ChatMessages
  • Per-user scoping: Pass a cognee user UUID as user_id to scope writes and searches

Installation

Requires Python 3.10+. The package depends on haystack-ai>=2.24.0 and cognee>=1.0.9.

Quick Start

Set your keys (cognee extracts knowledge with an LLM; Haystack’s OpenAIChatGenerator reads OPENAI_API_KEY):
Store some facts, then build a pipeline that injects retrieved memories ahead of the user’s message:
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 a session_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

  1. Write: CogneeWriter stores message text with cognee.remember, batched into one call on the permanent tier, or one entry per message on the session tier. Empty messages are skipped.
  2. Retrieve: CogneeRetriever runs cognee.recall against the store’s dataset and wraps each result in a system ChatMessage
  3. Inject: An OutputAdapter (or any component you like) prepends the memories to the user’s messages before the Agent runs
  4. Improve: improve() runs cognee.improve to enrich the graph and promote session content into it

GitHub Repository

View source code and examples

Examples

Runnable memory agent demo