LlamaIndex Graph RAG Integration: Cognee
Cognee assists developers in introducing greater predictability and management into their Retrieval-Augmented Generation (RAG) workflows through the use of graph architectures, vector stores, and auto-optimizing pipelines. Displaying information as a graph is the clearest way to grasp the content of your documents. Crucially, graphs allow systematic navigation and extraction of data from documents based on their hierarchy.
This integration provides a seamless interface between LlamaIndex and Cognee, enabling you to:
- Build Knowledge Graphs from your documents automatically
- Search with Multiple Methods including vector search, graph traversal, and hybrid approaches
- Visualize Your Data with interactive HTML graph visualizations
- Scale with Enterprise Databases including PostgreSQL, Neo4j, and more
For more information, visit Cognee documentation
Installation
pip install llama-index-graph-rag-cognee
Usage
Basic Example
import os
import asyncio
from llama_index.core import Document
from llama_index.graph_rag.cognee import CogneeGraphRAG
async def main():
# Initialize CogneeGraphRAG
cognee_rag = CogneeGraphRAG(
llm_api_key=os.environ["OPENAI_API_KEY"],
llm_provider="openai",
llm_model="gpt-4o-mini",
graph_db_provider="kuzu", # or "neo4j", "networkx"
vector_db_provider="lancedb",
relational_db_provider="sqlite",
relational_db_name="cognee_db",
)
# Create documents
documents = [
Document(
text="Apple Inc. is a technology company founded by Steve Jobs."
),
Document(
text="Steve Jobs was the CEO of Apple and known for innovation."
),
Document(text="The iPhone was released by Apple in 2007."),
]
# Add documents to the knowledge graph
await cognee_rag.add(documents, dataset_name="apple_knowledge")
# Process data into the knowledge graph
await cognee_rag.process_data("apple_knowledge")
# Search the knowledge graph
results = await cognee_rag.search("Who founded Apple?")
print("Search Results:", results)
# Generate and visualize the knowledge graph
viz_path = await cognee_rag.visualize_graph(
open_browser=True, # Automatically open in browser
output_file_path=".", # Save to current directory
)
print(f"Visualization saved to: {viz_path}")
if __name__ == "__main__":
asyncio.run(main())
Advanced Usage
import os
import pandas as pd
import asyncio
from llama_index.core import Document
from llama_index.graph_rag.cognee import CogneeGraphRAG
async def advanced_example():
# Load news data
news = pd.read_csv(
"https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/news_articles.csv"
)[:5]
documents = [
Document(text=f"{row['title']}: {row['text']}")
for i, row in news.iterrows()
]
# Initialize with enterprise databases
cognee_rag = CogneeGraphRAG(
llm_api_key=os.environ["OPENAI_API_KEY"],
llm_provider="openai",
llm_model="gpt-4o-mini",
graph_db_provider="neo4j", # Enterprise graph database
vector_db_provider="qdrant", # Scalable vector database
relational_db_provider="postgresql",
relational_db_name="cognee_production",
)
# Build knowledge graph
await cognee_rag.add(documents, "news_dataset")
await cognee_rag.process_data("news_dataset")
# Multiple search approaches
print("=== Graph-based Search ===")
graph_results = await cognee_rag.search(
"Tell me about the people mentioned"
)
for result in graph_results:
print(f"📊 {result}")
print("\n=== RAG-based Search ===")
rag_results = await cognee_rag.rag_search(
"Tell me about the people mentioned"
)
for result in rag_results:
print(f"🔍 {result}")
print("\n=== Related Nodes ===")
related = await cognee_rag.get_related_nodes("person")
for node in related:
print(f"🔗 {node}")
# Generate visualization
await cognee_rag.visualize_graph(
open_browser=False, output_file_path="/path/to/your/output/directory"
)
if __name__ == "__main__":
asyncio.run(advanced_example())
Key Features
🔍 Multiple Search Methods
search()- Graph-based search using knowledge graph relationshipsrag_search()- Traditional RAG search using vector similarityget_related_nodes()- Find connected entities and relationships
📊 Graph Visualization
- Interactive HTML visualization of your knowledge graph
- Automatic browser opening for immediate viewing
- Customizable output paths for saving visualizations
- Built on D3.js for rich, interactive exploration
🏗️ Flexible Architecture
- Multiple database backends for different scale requirements
- Async-first design for high-performance applications
- LlamaIndex Document integration for seamless workflows
- Enterprise-ready with PostgreSQL, Neo4j, and Qdrant support
🎯 Dataset Management
- Organize data by datasets for logical separation
- Process datasets independently for better control
- Future support for advanced dataset operations
API Reference
CogneeGraphRAG Methods
| Method | Description | Parameters |
|---|---|---|
add() |
Add documents to the knowledge graph | data: Documents, dataset_name: String |
process_data() |
Process data into graph structure | dataset_names: String |
search() |
Graph-based search | query: String |
rag_search() |
Vector similarity search | query: String |
get_related_nodes() |
Find related entities | node_id: String |
visualize_graph() |
Generate HTML visualization | open_browser: Bool, output_file_path: Optional[String] |
Supported Databases
Relational databases: SQLite, PostgreSQL
Vector databases: LanceDB, PGVector, QDrant, Weaviate
Graph databases: Neo4j, NetworkX, Kuzu
Metadata
Release files for llama-index-graph-rag-cognee 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llama_index_graph_rag_cognee-0.4.0.tar.gz | 8.2 kB | Without provenance | Details for llama_index_graph_rag_cognee-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llama_index_graph_rag_cognee-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for llama_index_graph_rag_cognee-0.4.0-py3-none-any.whl |
Total release size: 17.1 kB
Release files / llama_index_graph_rag_cognee-0.4.0.tar.gz
| Download URL | llama_index_graph_rag_cognee-0.4.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7310431b2b2b7cd4c925b493248ffdb57c3fe7a5f0f3f64c5a8b35ffc2f2f839
|
|
BLAKE2b-256 checksum How to use checksums |
3fb234e6250e418b376a1adcf6702a9d5e7503dc05310a17839a838c3a56ce7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / llama_index_graph_rag_cognee-0.4.0-py3-none-any.whl
| Download URL | llama_index_graph_rag_cognee-0.4.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d9dc03993b1cfdfd3c9f07bdb8f800b44cb776438a47397f17f5f0d172570e0
|
|
BLAKE2b-256 checksum How to use checksums |
914783bfa5c02ac1cadee3e85ed66839ee80ff0d186a74c112e62516778fd7aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for llama-index-graph-rag-cognee 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.