Skip to content

Commit 88621ba

Browse files
committed
add cognee
1 parent bb50b4a commit 88621ba

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Implementation of the cognee for AgentStack.
3+
These functions wrap cognee's asynchronous methods and expose them
4+
as synchronous functions with typed parameters & docstrings for use by AI agents.
5+
"""
6+
7+
import cognee
8+
import asyncio
9+
from typing import List
10+
from cognee.api.v1.search import SearchType
11+
12+
13+
def prune_data(metadata: bool = False) -> str:
14+
"""
15+
Prune the cognee data. If metadata is True, also prune system metadata.
16+
17+
:param metadata: Whether to prune system metadata as well.
18+
:return: A confirmation message.
19+
"""
20+
21+
async def _prune():
22+
await cognee.prune.prune_data()
23+
if metadata:
24+
await cognee.prune.prune_system(metadata=True)
25+
return "Data pruned successfully."
26+
27+
return asyncio.run(_prune())
28+
29+
30+
def add_text(text: str) -> str:
31+
"""
32+
Add text to cognee's knowledge system for future 'cognify' operations.
33+
34+
:param text: The text to add.
35+
:return: A confirmation message.
36+
"""
37+
38+
async def _add():
39+
await cognee.add(text)
40+
return "Text added successfully."
41+
42+
return asyncio.run(_add())
43+
44+
45+
def cognify() -> str:
46+
"""
47+
Run cognee's 'cognify' pipeline to build the knowledge graph,
48+
summaries, and other metadata from previously added text.
49+
50+
:return: A confirmation message.
51+
"""
52+
53+
async def _cognify():
54+
await cognee.cognify()
55+
return "Cognify process complete."
56+
57+
return asyncio.run(_cognify())
58+
59+
60+
def search_insights(query_text: str) -> str:
61+
"""
62+
Perform an INSIGHTS search on the knowledge graph for the given query text.
63+
64+
:param query_text: The query to search for.
65+
:return: The search results as a (stringified) list of matches.
66+
"""
67+
68+
async def _search():
69+
results = await cognee.search(SearchType.INSIGHTS, query_text=query_text)
70+
return str(results)
71+
72+
return asyncio.run(_search())
73+
74+
def search_summaries(query_text: str) -> str:
75+
"""
76+
Perform a SUMMARIES search on the knowledge graph for the given query text.
77+
78+
:param query_text: The query to search for.
79+
:return: The search results as a (stringified) list of matches.
80+
"""
81+
82+
async def _search():
83+
results = await cognee.search(SearchType.SUMMARIES, query_text=query_text)
84+
return str(results)
85+
86+
return asyncio.run(_search())
87+
88+
def search_chunks(query_text: str) -> str:
89+
"""
90+
Perform a CHUNKS search on the knowledge graph for the given query text.
91+
92+
:param query_text: The query to search for.
93+
:return: The search results as a (stringified) list of matches.
94+
"""
95+
96+
async def _search():
97+
results = await cognee.search(SearchType.CHUNKS, query_text=query_text)
98+
return str(results)
99+
100+
return asyncio.run(_search())
101+
102+
def search_completion(query_text: str) -> str:
103+
"""
104+
Perform a COMPLETION search on the knowledge graph for the given query text.
105+
106+
:param query_text: The query to search for.
107+
:return: The search results as a (stringified) list of matches.
108+
"""
109+
110+
async def _search():
111+
results = await cognee.search(SearchType.COMPLETION, query_text=query_text)
112+
return str(results)
113+
114+
return asyncio.run(_search())
115+
116+
def search_graph_completion(query_text: str) -> str:
117+
"""
118+
Perform a GRAPH_COMPLETION search on the knowledge graph for the given query text.
119+
120+
:param query_text: The query to search for.
121+
:return: The search results as a (stringified) list of matches.
122+
"""
123+
124+
async def _search():
125+
results = await cognee.search(SearchType.GRAPH_COMPLETION, query_text=query_text)
126+
return str(results)
127+
128+
return asyncio.run(_search())
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "cognee",
3+
"category": "Memory",
4+
"tools": [
5+
"prune_data",
6+
"add_text",
7+
"cognify",
8+
"search_insights"
9+
],
10+
"url": "https://github.com/topoteretes/cognee",
11+
"tools_bundled": true,
12+
"cta": "Cognee installed! Please set your cognee env variables.",
13+
14+
"env": {
15+
"ENV": "local",
16+
"TOKENIZERS_PARALLELISM": "false",
17+
"LLM_API_KEY": "",
18+
"LLM_MODEL": "openai/gpt-4o-mini",
19+
"LLM_PROVIDER": "openai",
20+
"LLM_ENDPOINT": "",
21+
"LLM_API_VERSION": "",
22+
"GRAPHISTRY_USERNAME": "",
23+
"GRAPHISTRY_PASSWORD": "",
24+
"SENTRY_REPORTING_URL": "",
25+
"EMBEDDING_PROVIDER": "openai",
26+
"EMBEDDING_API_KEY": "",
27+
"EMBEDDING_MODEL": "openai/text-embedding-3-large",
28+
"EMBEDDING_ENDPOINT": "",
29+
"EMBEDDING_API_VERSION": "",
30+
"EMBEDDING_DIMENSIONS": 3072,
31+
"EMBEDDING_MAX_TOKENS": 8191,
32+
"_comment1": "# neo4j or networkx",
33+
"GRAPH_DATABASE_PROVIDER": "networkx",
34+
"_comment2": "# Not needed if using networkx",
35+
"GRAPH_DATABASE_URL": "",
36+
"GRAPH_DATABASE_USERNAME": "",
37+
"GRAPH_DATABASE_PASSWORD": "",
38+
"_comment3": "# qdrant, pgvector, weaviate, milvus or lancedb",
39+
"VECTOR_DB_PROVIDER": "lancedb",
40+
"_comment4": "# Not needed if using lancedb or pgvector",
41+
"VECTOR_DB_URL": "",
42+
"VECTOR_DB_KEY": "",
43+
"_comment5": "Relational Database provider sqlite or postgres",
44+
"DB_PROVIDER": "sqlite",
45+
"_comment6": "# Database name",
46+
"DB_NAME": "cognee_db",
47+
"_comment7": "# Postgres specific parameters (Only if Postgres or PGVector is used)",
48+
"DB_HOST": "127.0.0.1",
49+
"DB_PORT": 5432,
50+
"DB_USERNAME": "cognee",
51+
"DB_PASSWORD": "cognee"
52+
},
53+
54+
"packages": [
55+
"cognee[postgres,neo4j]"
56+
],
57+
"post_install": "Now, you can start cognifying!",
58+
"post_remove": "Cognee is removed!"
59+
}
60+

0 commit comments

Comments
 (0)