Repository navigation
Add the cognee integration page #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6d190d
Add the cognee integration page
bilgeyucel d570da7
add missing logo
bilgeyucel 744f8ff
Add the cognee integration page
bilgeyucel ddc5b43
add missing logo
bilgeyucel f535575
Merge branch 'cognee-integratinon' of github.com:deepset-ai/haystack-…
bilgeyucel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| --- | ||
| layout: integration | ||
| name: Cognee | ||
| description: Add persistent, knowledge-graph-backed memory to your Haystack agents and pipelines with Cognee | ||
| authors: | ||
| - name: deepset | ||
| socials: | ||
| github: deepset-ai | ||
| twitter: haystack_ai | ||
| linkedin: https://www.linkedin.com/company/deepset-ai/ | ||
| - name: Cognee | ||
| socials: | ||
| github: topoteretes | ||
| twitter: cognee_ai | ||
| linkedin: https://www.linkedin.com/company/cognee-ai/ | ||
| pypi: https://pypi.org/project/cognee-haystack/ | ||
| repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cognee | ||
| type: Memory Store | ||
| report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues | ||
| logo: /logos/cognee.png | ||
| version: Haystack 2.0 | ||
| toc: true | ||
| --- | ||
|
|
||
| ### **Table of Contents** | ||
|
|
||
| - [Overview](#overview) | ||
| - [Installation](#installation) | ||
| - [Usage](#usage) | ||
| - [Available Classes](#available-classes) | ||
| - [Use in a Pipeline](#use-in-a-pipeline) | ||
| - [License](#license) | ||
|
|
||
| ## Overview | ||
|
|
||
| [Cognee](https://www.cognee.ai/) provides open-source, knowledge-graph-backed memory for AI agents and assistants. It helps Haystack applications store facts, conversation history, and contextual knowledge as a semantic graph, then retrieve the most relevant memories using graph-completion or other search strategies. | ||
|
|
||
| The `cognee-haystack` package is part of [Haystack Core Integrations](https://github.com/deepset-ai/haystack-core-integrations) and provides: | ||
|
|
||
| - `CogneeMemoryStore`: A persistent memory store backed by Cognee's knowledge graph API. | ||
| - `CogneeRetriever`: A pipeline component for retrieving memories from Cognee as system `ChatMessage` objects. | ||
| - `CogneeWriter`: A pipeline component for writing `ChatMessage` memories to Cognee. | ||
|
|
||
| Cognee supports two memory tiers: | ||
|
|
||
| - **Permanent knowledge graph** — rich semantic storage backed by an LLM extraction step; supports graph-completion queries and cross-session recall. | ||
| - **Session cache** — fast, LLM-free writes scoped to a single session; can be promoted to the permanent graph later via `CogneeMemoryStore.improve()`. | ||
|
|
||
| ## Installation | ||
|
|
||
| Install the integration: | ||
|
|
||
| ```bash | ||
| pip install cognee-haystack | ||
| ``` | ||
|
|
||
| Set your LLM API key (used by Cognee for knowledge graph extraction and queries): | ||
|
|
||
| ```bash | ||
| export LLM_API_KEY="your-llm-api-key" | ||
| ``` | ||
|
|
||
| Optionally, set a separate embedding API key (defaults to `LLM_API_KEY` when unset): | ||
|
|
||
| ```bash | ||
| export EMBEDDING_API_KEY="your-embedding-api-key" | ||
| ``` | ||
|
bilgeyucel marked this conversation as resolved.
|
||
|
|
||
| Cognee reads LLM provider, database, and vector-store settings from environment variables. See the [Cognee documentation](https://docs.cognee.ai) for the full list of configuration options. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Available Classes | ||
|
|
||
| - [`CogneeRetriever`](https://docs.haystack.deepset.ai/docs/cogneeretriever): Retrieves memories from Cognee as system `ChatMessage` objects. | ||
| - [`CogneeWriter`](https://docs.haystack.deepset.ai/docs/cogneewriter): Writes `ChatMessage` objects to Cognee. | ||
| - [`CogneeMemoryStore`](https://docs.haystack.deepset.ai/reference/integrations-cognee#cogneememorystore): The underlying store that wraps Cognee's V2 memory API (`remember`, `recall`, `improve`, `forget`). | ||
|
|
||
| ### Use in a Pipeline | ||
|
|
||
| Use `CogneeRetriever` and `CogneeWriter` for explicit pipeline control over when memories are stored and retrieved. | ||
|
|
||
| The example below seeds long-lived facts into the permanent knowledge graph, then runs an agent pipeline that retrieves relevant context before each response. `cognee.recall` auto-captures each turn as a session QA entry, so no `CogneeWriter` is needed inside the agent pipeline for session memory. | ||
|
|
||
| ```python | ||
| from haystack import Pipeline | ||
| from haystack.components.agents import Agent | ||
| from haystack.components.converters import OutputAdapter | ||
| from haystack.components.generators.chat import OpenAIChatGenerator | ||
| from haystack.dataclasses import ChatMessage | ||
|
|
||
| from haystack_integrations.components.retrievers.cognee import CogneeRetriever | ||
| from haystack_integrations.components.writers.cognee import CogneeWriter | ||
| from haystack_integrations.memory_stores.cognee import CogneeMemoryStore | ||
|
|
||
| # Seed long-lived facts into the permanent knowledge graph (no session_id). | ||
| seed_store = CogneeMemoryStore(dataset_name="my_agent_memory", self_improvement=False) | ||
| persistent_writer = CogneeWriter(memory_store=seed_store) | ||
| persistent_writer.run( | ||
| messages=[ | ||
| ChatMessage.from_user("Alice is a senior data scientist specialising in NLP."), | ||
| ChatMessage.from_user("Alice's current project is a documentation search system built with Haystack."), | ||
| ChatMessage.from_user("Alice prefers concise answers with Python code examples."), | ||
| ] | ||
| ) | ||
|
|
||
| # Build the agent pipeline with a session-scoped store. | ||
| SESSION = "alice_session_1" | ||
| chat_store = CogneeMemoryStore(dataset_name="my_agent_memory", session_id=SESSION) | ||
|
|
||
| pipeline = Pipeline() | ||
| pipeline.add_component("retriever", CogneeRetriever(memory_store=chat_store)) | ||
| pipeline.add_component( | ||
| "memory_context", | ||
| OutputAdapter( | ||
| template="{{ memories + user_messages }}", | ||
| output_type=list[ChatMessage], | ||
| unsafe=True, | ||
| ), | ||
| ) | ||
| pipeline.add_component( | ||
| "agent", | ||
| Agent( | ||
| chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"), | ||
| system_prompt=( | ||
| "You are a helpful assistant with long-term memory. " | ||
| "System messages at the start of the conversation contain relevant memories. " | ||
| "Be concise; prefer short answers and Python code examples." | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| pipeline.connect("retriever.messages", "memory_context.memories") | ||
| pipeline.connect("memory_context.output", "agent.messages") | ||
|
|
||
| query = "What project is Alice currently working on?" | ||
| result = pipeline.run( | ||
| { | ||
| "retriever": {"query": query}, | ||
| "memory_context": {"user_messages": [ChatMessage.from_user(query)]}, | ||
| } | ||
| ) | ||
| print(result["agent"]["last_message"].text) | ||
|
|
||
| # After the session, promote the session cache into the permanent graph. | ||
| chat_store.improve() | ||
| ``` | ||
|
|
||
| For a full four-phase demo (persistent seeding → session seeding → agent chat → graph promotion), see the [example script](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/cognee/examples/demo_memory_agent.py). | ||
|
|
||
| ## License | ||
|
|
||
| `cognee-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.