uses? #5262
Unanswered
7soumyajitghosh
asked this question in
Q&A
uses?
#5262
Replies: 1 comment
|
To use Cognee in a production-ready and reliable way, it helps to understand its underlying architecture: Cognee is not just a vector wrapper, but a hybrid Memory Engine that builds an interconnected Knowledge Graph (entities and relationships) alongside vector embeddings. Here is an architectural walkthrough and practical guide to using Cognee properly: 1. The Core Lifecycle (Add -> Cognify -> Search)A proper Cognee pipeline follows three distinct phases:
2. Recommended Production ArchitectureFor development, Cognee works out of the box with local defaults (SQLite + NetworkX + LanceDB). For reliable production use, configure dedicated backends in your
3. Complete Python Implementation PatternHere is a clean, async implementation following best practices: import asyncio
import os
import cognee
from cognee import SearchType
# 1. Configure environment variables (LLM & Embeddings)
os.environ["LLM_API_KEY"] = "your-api-key"
os.environ["LLM_MODEL"] = "gpt-4o-mini" # Fast extraction model for cognify
os.environ["EMBEDDING_MODEL"] = "text-embedding-3-small"
async def main():
dataset_name = "production_knowledge_base"
# Step 1: Ingest documents into an isolated dataset namespace
raw_document = """
Aetheria Studio builds high-performance multiplayer game systems on Roblox.
Their primary networking engine utilizes RollbackBuffer for 120-tick lag compensation.
Rustaman Delvianova serves as the lead architecture engineer for the collective.
"""
print("[1/3] Adding documents...")
await cognee.add(raw_document, dataset_name = dataset_name)
# Step 2: Cognify (generate knowledge graph + embeddings)
print("[2/3] Cognifying knowledge graph...")
await cognee.cognify(datasets = [dataset_name])
# Step 3: Search using the appropriate search mode
print("[3/3] Querying memory...")
# Mode A: INSIGHTS (traverses graph edges for relational reasoning)
insights = await cognee.search(
SearchType.INSIGHTS,
query = "Who is the lead engineer for Aetheria Studio and what netcode do they use?",
datasets = [dataset_name],
)
print("\n--- Insights (Knowledge Graph Traversal) ---")
for insight in insights:
print(insight)
# Mode B: CHUNKS (direct semantic text chunk retrieval)
chunks = await cognee.search(
SearchType.CHUNKS,
query = "RollbackBuffer tick rate",
datasets = [dataset_name],
)
print("\n--- Semantic Chunks ---")
for chunk in chunks:
print(chunk)
if __name__ == "__main__":
asyncio.run(main())4. Key Best Practices to Avoid Pitfalls
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
How we use it in a proper way?
All reactions