Skip to main content

llama-index graph rag cognee integration

Project description

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.

For more information, visit Cognee documentation

Installation

pip install llama-index-graph-rag-cognee

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 example_graph_rag_cognee():
    # Gather documents to add to GraphRAG
    news = pd.read_csv(
        "https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/news_articles.csv"
    )[:5]
    news.head()
    documents = [
        Document(text=f"{row['title']}: {row['text']}")
        for i, row in news.iterrows()
    ]

    # Instantiate cognee GraphRAG
    cogneeRAG = CogneeGraphRAG(
        llm_api_key=os.environ["OPENAI_API_KEY"],
        llm_provider="openai",
        llm_model="gpt-4o-mini",
        graph_db_provider="networkx",
        vector_db_provider="lancedb",
        relational_db_provider="sqlite",
        relational_db_name="cognee_db",
    )

    # Add data to cognee
    await cogneeRAG.add(documents, "test")

    # Process data into a knowledge graph
    await cogneeRAG.process_data("test")

    # Answer prompt based on knowledge graph
    search_results = await cogneeRAG.search(
        "Tell me who are the people mentioned?"
    )
    print("\n\nAnswer based on knowledge graph:\n")
    for result in search_results:
        print(f"{result}\n")

    # Answer prompt based on RAG
    search_results = await cogneeRAG.rag_search(
        "Tell me who are the people mentioned?"
    )
    print("\n\nAnswer based on RAG:\n")
    for result in search_results:
        print(f"{result}\n")

    # Search for related nodes in graph
    search_results = await cogneeRAG.get_related_nodes("person")
    print("\n\nRelated nodes are:\n")
    for result in search_results:
        print(f"{result}\n")


if __name__ == "__main__":
    asyncio.run(example_graph_rag_cognee())

Supported databases

Relational databases: SQLite, PostgreSQL

Vector databases: LanceDB, PGVector, QDrant, Weviate

Graph databases: Neo4j, NetworkX

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_graph_rag_cognee-0.1.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_graph_rag_cognee-0.1.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_graph_rag_cognee-0.1.3.tar.gz.

File metadata

  • Download URL: llama_index_graph_rag_cognee-0.1.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1020-azure

File hashes

Hashes for llama_index_graph_rag_cognee-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5c20f26cd7a7641f9729e9c5356ea68b6b98e93effa1c2c61c0b6ffcf414405f
MD5 ed6262de5cc3a02dfa8166249154f596
BLAKE2b-256 f419a22e8b20a16db2dd01acb2225839c2aae52d71ec2b32d791073f1f4fcba6

See more details on using hashes here.

File details

Details for the file llama_index_graph_rag_cognee-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_graph_rag_cognee-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7d29b9fd7e2392d57cb169bab1af5e03058b7d362df1a153254abef32e357d94
MD5 2d71e70c0698cb29afab4dfdea810675
BLAKE2b-256 0d8904bbc5411323749cc71c167385aa260f42321ac61734b4545aea0778182c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page