Cognee
Cognee is a framework for AI memory and knowledge graphs. It uses an LLM to extract concepts and relationships from text, stores them as a knowledge graph and searches them. The Memgraph adapter, from the Cognee community packages, stores the graph in Memgraph. You can also follow the Jupyter notebook example.
Installation
Start Memgraph, for example in Docker:
docker run -p 7687:7687 memgraph/memgraph-mage:latestInstall Cognee with the Memgraph adapter:
pip install cognee cognee-community-graph-adapter-memgraphCognee calls an LLM to extract the graph. Set your LLM API key, for example
LLM_API_KEY for OpenAI, as described in the Cognee
docs.
Use Cognee with Memgraph
Register the adapter, point Cognee at Memgraph, then add text, build the graph and search it:
import asyncio
import cognee
from cognee_community_graph_adapter_memgraph import register
async def main():
# Register the Memgraph adapter and use it as the graph database
register()
cognee.config.set_graph_database_provider("memgraph")
cognee.config.set_graph_db_config(
{
"graph_database_url": "bolt://localhost:7687",
"graph_database_username": "",
"graph_database_password": "",
}
)
text = "Natural language processing (NLP) is a subfield of computer science focused on the interaction between computers and human language."
# Store the text
await cognee.add(text)
# Extract a knowledge graph with the LLM and store it in Memgraph
await cognee.cognify()
# Search the graph
results = await cognee.search(
query_type=cognee.SearchType.GRAPH_COMPLETION, query_text="What is NLP?"
)
for result in results:
print(result)
asyncio.run(main())How it works
cognee.add()stores the input text.cognee.cognify()extracts concepts and relationships with the LLM and stores them in Memgraph as a graph.cognee.search()answers the question from the graph, withGRAPH_COMPLETIONcombining graph context and the LLM.
For more examples, see the adapter README.