Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.0
128 changes: 128 additions & 0 deletions agentstack/_tools/cognee/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""
Implementation of the cognee for AgentStack.
These functions wrap cognee's asynchronous methods and expose them
as synchronous functions with typed parameters & docstrings for use by AI agents.
"""

import cognee
import asyncio
from typing import List
from cognee.api.v1.search import SearchType

Check warning on line 10 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L8-L10

Added lines #L8 - L10 were not covered by tests


def prune_data(metadata: bool = False) -> str:

Check warning on line 13 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L13

Added line #L13 was not covered by tests
"""
Prune the cognee data. If metadata is True, also prune system metadata.

:param metadata: Whether to prune system metadata as well.
:return: A confirmation message.
"""

async def _prune():
await cognee.prune.prune_data()

Check warning on line 22 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L21-L22

Added lines #L21 - L22 were not covered by tests
if metadata:
await cognee.prune.prune_system(metadata=True)
return "Data pruned successfully."

Check warning on line 25 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L24-L25

Added lines #L24 - L25 were not covered by tests

return asyncio.run(_prune())

Check warning on line 27 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L27

Added line #L27 was not covered by tests


def add_text(text: str) -> str:

Check warning on line 30 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L30

Added line #L30 was not covered by tests
"""
Add text to cognee's knowledge system for future 'cognify' operations.

:param text: The text to add.
:return: A confirmation message.
"""

async def _add():
await cognee.add(text)
return "Text added successfully."

Check warning on line 40 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L38-L40

Added lines #L38 - L40 were not covered by tests

return asyncio.run(_add())

Check warning on line 42 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L42

Added line #L42 was not covered by tests


def cognify() -> str:

Check warning on line 45 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L45

Added line #L45 was not covered by tests
"""
Run cognee's 'cognify' pipeline to build the knowledge graph,
summaries, and other metadata from previously added text.

:return: A confirmation message.
"""

async def _cognify():
await cognee.cognify()
return "Cognify process complete."

Check warning on line 55 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L53-L55

Added lines #L53 - L55 were not covered by tests

return asyncio.run(_cognify())

Check warning on line 57 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L57

Added line #L57 was not covered by tests


def search_insights(query_text: str) -> str:

Check warning on line 60 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L60

Added line #L60 was not covered by tests
"""
Perform an INSIGHTS search on the knowledge graph for the given query text.

:param query_text: The query to search for.
:return: The search results as a (stringified) list of matches.
"""

async def _search():
results = await cognee.search(SearchType.INSIGHTS, query_text=query_text)
return str(results)

Check warning on line 70 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L68-L70

Added lines #L68 - L70 were not covered by tests

return asyncio.run(_search())

Check warning on line 72 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L72

Added line #L72 was not covered by tests

def search_summaries(query_text: str) -> str:

Check warning on line 74 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L74

Added line #L74 was not covered by tests
"""
Perform a SUMMARIES search on the knowledge graph for the given query text.

:param query_text: The query to search for.
:return: The search results as a (stringified) list of matches.
"""

async def _search():
results = await cognee.search(SearchType.SUMMARIES, query_text=query_text)
return str(results)

Check warning on line 84 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L82-L84

Added lines #L82 - L84 were not covered by tests

return asyncio.run(_search())

Check warning on line 86 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L86

Added line #L86 was not covered by tests

def search_chunks(query_text: str) -> str:

Check warning on line 88 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L88

Added line #L88 was not covered by tests
"""
Perform a CHUNKS search on the knowledge graph for the given query text.

:param query_text: The query to search for.
:return: The search results as a (stringified) list of matches.
"""

async def _search():
results = await cognee.search(SearchType.CHUNKS, query_text=query_text)
return str(results)

Check warning on line 98 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L96-L98

Added lines #L96 - L98 were not covered by tests

return asyncio.run(_search())

Check warning on line 100 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L100

Added line #L100 was not covered by tests

def search_completion(query_text: str) -> str:

Check warning on line 102 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L102

Added line #L102 was not covered by tests
"""
Perform a COMPLETION search on the knowledge graph for the given query text.

:param query_text: The query to search for.
:return: The search results as a (stringified) list of matches.
"""

async def _search():
results = await cognee.search(SearchType.COMPLETION, query_text=query_text)
return str(results)

Check warning on line 112 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L110-L112

Added lines #L110 - L112 were not covered by tests

return asyncio.run(_search())

Check warning on line 114 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L114

Added line #L114 was not covered by tests

def search_graph_completion(query_text: str) -> str:

Check warning on line 116 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L116

Added line #L116 was not covered by tests
"""
Perform a GRAPH_COMPLETION search on the knowledge graph for the given query text.

:param query_text: The query to search for.
:return: The search results as a (stringified) list of matches.
"""

async def _search():
results = await cognee.search(SearchType.GRAPH_COMPLETION, query_text=query_text)
return str(results)

Check warning on line 126 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L124-L126

Added lines #L124 - L126 were not covered by tests

return asyncio.run(_search())

Check warning on line 128 in agentstack/_tools/cognee/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/cognee/__init__.py#L128

Added line #L128 was not covered by tests
64 changes: 64 additions & 0 deletions agentstack/_tools/cognee/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "cognee",
"category": "Memory",
"tools": [
"prune_data",
"add_text",
"cognify",
"search_insights",
"search_summaries",
"search_chunks",
"search_completion",
"search_graph_completion"
],
"url": "https://github.com/topoteretes/cognee",
"tools_bundled": true,
"cta": "Cognee installed! Please set your cognee env variables.",

"env": {
"ENV": "local",
"TOKENIZERS_PARALLELISM": "false",
"LLM_API_KEY": "",
"LLM_MODEL": "openai/gpt-4o-mini",
"LLM_PROVIDER": "openai",
"LLM_ENDPOINT": "",
"LLM_API_VERSION": "",
"GRAPHISTRY_USERNAME": "",
"GRAPHISTRY_PASSWORD": "",
"SENTRY_REPORTING_URL": "",
"EMBEDDING_PROVIDER": "openai",
"EMBEDDING_API_KEY": "",
"EMBEDDING_MODEL": "openai/text-embedding-3-large",
"EMBEDDING_ENDPOINT": "",
"EMBEDDING_API_VERSION": "",
"EMBEDDING_DIMENSIONS": 3072,
"EMBEDDING_MAX_TOKENS": 8191,
"_comment1": "# neo4j or networkx",
"GRAPH_DATABASE_PROVIDER": "networkx",
"_comment2": "# Not needed if using networkx",
"GRAPH_DATABASE_URL": "",
"GRAPH_DATABASE_USERNAME": "",
"GRAPH_DATABASE_PASSWORD": "",
"_comment3": "# qdrant, pgvector, weaviate, milvus or lancedb",
"VECTOR_DB_PROVIDER": "lancedb",
"_comment4": "# Not needed if using lancedb or pgvector",
"VECTOR_DB_URL": "",
"VECTOR_DB_KEY": "",
"_comment5": "Relational Database provider sqlite or postgres",
"DB_PROVIDER": "sqlite",
"_comment6": "# Database name",
"DB_NAME": "cognee_db",
"_comment7": "# Postgres specific parameters (Only if Postgres or PGVector is used)",
"DB_HOST": "127.0.0.1",
"DB_PORT": 5432,
"DB_USERNAME": "cognee",
"DB_PASSWORD": "cognee"
},

"packages": [
"cognee"
],
"post_install": "Now, you can start cognifying!",
"post_remove": "Cognee is removed!"
}

Loading
Loading