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",
        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("person")
    print("\n\nExtracted sentences are:\n")
    for result in search_results:
        print(f"{result}\n")

    # Search for related nodes
    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())

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.0.tar.gz (4.1 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.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llama_index_graph_rag_cognee-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 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.0.tar.gz
Algorithm Hash digest
SHA256 1f1579b3db2466f72f097307f5ff7ea1a8d658e85838c95b6997dfadf86a7083
MD5 a12221b7aa0ab45ac3014e0b44477ec4
BLAKE2b-256 2af9b19d763a962b7bee3fc9b5ab7b61005b00aa44afbb157b0c54932f6456da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_graph_rag_cognee-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3385e55a9e2ffc55d29dc4aaeefcc97e8bda0eaf16e76f5fe2bd08702229573f
MD5 9411bc1513e838ebc8bf0cd35d4b7c57
BLAKE2b-256 51f34ec5e29c2ea7f3a5b324e54baa25c5be9bc34f9b6245951f12b4978ea097

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