|
1 | 1 | # cognee-haystack |
2 | 2 |
|
3 | | -[](https://pypi.org/project/cognee-haystack/) |
4 | | -[](LICENSE) |
| 3 | +[](https://pypi.org/project/cognee-haystack) |
| 4 | +[](https://pypi.org/project/cognee-haystack) |
5 | 5 |
|
6 | | -A [Haystack](https://haystack.deepset.ai/) integration for [Cognee](https://github.com/topoteretes/cognee) — open-source memory for AI agents. |
| 6 | +[Cognee](https://www.cognee.ai/) integration for [Haystack](https://haystack.deepset.ai/) — open-source memory for AI agents. |
7 | 7 |
|
8 | | -[Cognee](https://www.cognee.ai/) gives agents persistent, traceable memory by transforming raw data (e.g., unstructured documents, relational databases, etc.) into a knowledge engine that is both searchable by meaning and connected by relationships. Cognee uses an ECL (Extract, Cognify, Load) pipeline: vector search, knowledge graphs, with support for ontology-based entity grounding (e.g. OWL) and Pydantic-defined graph schemas. |
| 8 | +- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/cognee/CHANGELOG.md) |
9 | 9 |
|
10 | | -Cognee serves developers and teams building agentic systems where agents need to retain context across sessions, learn from user feedback, and operate in multi-tenant, data-isolated environments. Cognee is available as an open-source Python library (Apache 2.0), a self-hosted/on-prem subscription tier, and a managed cloud service (Cognee Cloud at platform.cognee.ai). |
| 10 | +--- |
11 | 11 |
|
| 12 | +## Contributing |
12 | 13 |
|
13 | | -## Installation |
14 | | - |
15 | | -```bash |
16 | | -pip install cognee-haystack |
17 | | -``` |
18 | | - |
19 | | -To use the `CogneeMemoryStore` with Haystack's experimental Agent: |
20 | | - |
21 | | -```bash |
22 | | -pip install "cognee-haystack[memory]" |
23 | | -``` |
24 | | - |
25 | | -## Components |
26 | | - |
27 | | -### CogneeWriter |
28 | | - |
29 | | -Adds Haystack Documents to Cognee's knowledge engine via `cognee.add()`, with optional automatic `cognee.cognify()`. |
30 | | - |
31 | | -```python |
32 | | -from haystack import Document, Pipeline |
33 | | -from haystack_integrations.components.connectors.cognee import CogneeWriter |
34 | | - |
35 | | -pipeline = Pipeline() |
36 | | -pipeline.add_component("writer", CogneeWriter(dataset_name="my_data", auto_cognify=True)) |
37 | | - |
38 | | -docs = [Document(content="Cognee builds a structured memory from unstructured data.")] |
39 | | -pipeline.run({"writer": {"documents": docs}}) |
40 | | -``` |
41 | | - |
42 | | -### CogneeCognifier |
43 | | - |
44 | | -Standalone `cognee.cognify()` step — useful when you want to separate adding and processing. |
45 | | - |
46 | | -```python |
47 | | -from haystack_integrations.components.connectors.cognee import CogneeCognifier |
48 | | - |
49 | | -cognifier = CogneeCognifier() |
50 | | -cognifier.run() # {"cognified": True} |
51 | | -``` |
52 | | - |
53 | | -### CogneeRetriever |
54 | | - |
55 | | -Searches Cognee's memory and returns Haystack `Document` objects. |
56 | | - |
57 | | -```python |
58 | | -from haystack import Pipeline |
59 | | -from haystack_integrations.components.connectors.cognee import CogneeRetriever |
60 | | - |
61 | | -pipeline = Pipeline() |
62 | | -pipeline.add_component("retriever", CogneeRetriever(search_type="GRAPH_COMPLETION", top_k=5)) |
63 | | - |
64 | | -result = pipeline.run({"retriever": {"query": "What is Cognee?"}}) |
65 | | -for doc in result["retriever"]["documents"]: |
66 | | - print(doc.content) |
67 | | -``` |
68 | | - |
69 | | -**Supported search types:** `GRAPH_COMPLETION`, `CHUNKS`, `SUMMARIES`, `INSIGHTS`, and others from Cognee's `SearchType` enum. |
70 | | - |
71 | | -### CogneeMemoryStore |
72 | | - |
73 | | -Memory backend for Haystack's experimental Agent, backed by Cognee. |
74 | | - |
75 | | -```python |
76 | | -from haystack.dataclasses import ChatMessage |
77 | | -from haystack_integrations.components.connectors.cognee import CogneeMemoryStore |
78 | | - |
79 | | -store = CogneeMemoryStore(search_type="GRAPH_COMPLETION", top_k=5) |
80 | | - |
81 | | -# Store memories |
82 | | -store.add_memories(messages=[ |
83 | | - ChatMessage.from_user("The project deadline is next Friday.") |
84 | | -]) |
85 | | - |
86 | | -# Recall memories |
87 | | -results = store.search_memories(query="When is the deadline?") |
88 | | -``` |
89 | | - |
90 | | -## Configuration |
91 | | - |
92 | | -Cognee uses environment variables for its LLM and storage configuration: |
93 | | - |
94 | | -```bash |
95 | | -export LLM_API_KEY="sk-..." |
96 | | -``` |
97 | | - |
98 | | -See the [Cognee documentation](https://docs.cognee.ai/) for additional configuration options. |
99 | | - |
100 | | -## Examples |
101 | | - |
102 | | -See the [`examples/`](examples/) directory for runnable demos: |
103 | | - |
104 | | -- **`demo_pipeline.py`** — Index documents and search with CogneeWriter + CogneeRetriever |
105 | | -- **`demo_memory_agent.py`** — Use CogneeMemoryStore as a conversational memory backend |
106 | | - |
107 | | -## Development |
108 | | - |
109 | | -```bash |
110 | | -cd integrations/cognee |
111 | | - |
112 | | -# Format and lint |
113 | | -hatch run fmt |
114 | | -hatch run fmt-check |
115 | | - |
116 | | -# Type checking |
117 | | -hatch run test:types |
118 | | - |
119 | | -# Run tests |
120 | | -hatch run test:unit |
121 | | -``` |
122 | | - |
123 | | -## License |
124 | | - |
125 | | -Apache 2.0 — see [LICENSE](LICENSE) for details. |
| 14 | +Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md). |
0 commit comments