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.1.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.1-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.1.tar.gz.

File metadata

  • Download URL: llama_index_graph_rag_cognee-0.1.1.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-1017-azure

File hashes

Hashes for llama_index_graph_rag_cognee-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9cf9cb69989d9c7b3b9ca09c24f29683b474b4fbe60aa03cac28df46f72f4fef
MD5 6ef3f40c751b42c96bf928cf498ccd61
BLAKE2b-256 80f624e1b11b95b8e7c56d109bbec54280516f6ba1efa72147b654f240829cdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_graph_rag_cognee-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b29defe7a351185b1decda4c0d4464fce90e8406898eaad404a7a023c4185ea
MD5 f3bc78552c46424bad793c540cd268e7
BLAKE2b-256 8d22a486c83138cb857eb99223b7ca1277c6ed51b55bed16a11cec7e6529a7b0

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