Skip to main content

A Python package for hybrid Graph + Vector RAG using completely Open Source tools

Project description

Graph_Vect_RAG

graph_vect_rag is a powerful Python package designed to manage and query knowledge bases using a combination of knowledge graph and vector stores. This package supports integration with GROQ language models, HuggingFace embeddings, and Neo4j graph stores to build and query hybrid retrieval-augmented generation (RAG) systems.

Features

  • Language Model (LLM) Integration: Supports multiple language models from GROQ for natural language processing.
  • Graph and Vector Store Management: Handles knowledge bases as a combination of graph and vector indexes.
  • Custom Retriever: Combines graph and vector store retrievers for more effective query results.
  • Embeddings with HuggingFace: Uses HuggingFace embeddings for vector indexing.
  • Neo4j Graph Store Integration: Manages graph stores using the Neo4j database.
  • Flexible Querying: Allows natural language queries to the knowledge base.

Installation

To install Graph_Vect_RAG, use pip:

pip install graph_vect_rag

Basic Setup

1. Initialize the Engine:

from graph_rag_engine import Graph_RAG_Engine

engine = Graph_RAG_Engine()

2. Configure the Language Model (LLM):

You can configure the language model using any model from the supported list provided at the end of the document:

  • Directly providing the API key:

    engine.configure_llm(
        model_id="model_name_from_supported_list",
        api_key="your_groq_api_key"
    )
    
  • Using an environment variable: Alternatively, you can set the API key in your environment by creating a .env file with the following content:

    GROQ_API_KEY=your_groq_api_key
    

    The package will automatically load the API key from the environment variable GROQ_API_KEY when the api_key argument is not provided.

Replace "model_name_from_supported_list" with any of the supported models listed at the end of the document, such as "llama-3.1-70b-versatile" or "llama-3.1-8b-instant".

3. Configure the Embedding Model:

You can configure the embedding model using any HuggingFace embedding model:

engine.configure_embedding_model(model_id="huggingface_model_name")

Replace "huggingface_model_name" with the name of any HuggingFace model you wish to use for embeddings (e.g., "sentence-transformers/all-MiniLM-L6-v2").

4. Configure the Graph Store:

You can configure the graph store with default values for username and url. The default values are username="neo4j" and url="bolt://localhost:7687":

engine.configure_graph_store(
    password="neo4j_password",
    username="neo4j",  # Default value
    url="bolt://localhost:7687"  # Default value
)

If you need to use different values, simply provide them as arguments to configure_graph_store.

Note: You need to have Neo4j installed and running. Additionally, make sure that APOC procedures are enabled in your Neo4j instance for full functionality with this package.

Create a Knowledge Base

To create a knowledge base from a document:

engine.create_knowledge_base(
    file_path="path/to/your/document.txt",
    knowledge_base_name="my_knowledge_base"
)

Load a Knowledge Base

To load an existing knowledge base:

engine.load_knowledge_base(knowledge_base_name="my_knowledge_base")

Query the Knowledge Base

To query the loaded knowledge base using natural language:

response = engine.query_knowledge_base("What is the capital of France?")
print(response)

Exception Handling

Graph_Vect_RAG provides custom exceptions to handle various error scenarios:

  • InvlaidModelIdException: Raised when an invalid model ID is provided.
  • StorageContextNotFoundException: Raised when the storage context is not configured.
  • LLMNotFoundException: Raised when the LLM is not configured.
  • EmbeddingModelNotFoundException: Raised when the embedding model is not configured.
  • KnowledgeBaseAlreadyExists: Raised when trying to create a knowledge base with an existing name.
  • KnowledgeBaseNotFound: Raised when attempting to load a non-existent knowledge base.
  • KnowledgeBaseNotConfigured: Raised when querying without selecting a knowledge base.

Supported GROQ Models

The following models are supported by the package:

  • llama-3.1-70b-versatile
  • llama-3.1-8b-instant
  • llama3-groq-70b-8192-tool-use-preview
  • llama3-groq-8b-8192-tool-use-preview
  • llama-guard-3-8b
  • llama3-70b-8192
  • llama3-8b-8192
  • mixtral-8x7b-32768
  • gemma-7b-it
  • gemma2-9b-it

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

graph_vect_rag-1.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

graph_vect_rag-1.0.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file graph_vect_rag-1.0.0.tar.gz.

File metadata

  • Download URL: graph_vect_rag-1.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for graph_vect_rag-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8c058ff846184edae72a2af76185a6941af5ebd4ab524e3d6a43dd562d133128
MD5 f1ec1d6a4a4c957ea2cce76f94ada151
BLAKE2b-256 176d338a422e55416f3b978d8607e2077ad4521a59759dae398e10d6e243c20f

See more details on using hashes here.

File details

Details for the file graph_vect_rag-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graph_vect_rag-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7603652d278787dd6431ba3702e18c1325780089281915944b36e41b282c79ac
MD5 1a1a0c18bd2ad6b629ebdea43d458536
BLAKE2b-256 bd3fdee4916a182bbac2cda3c0144d46d7e3a48e4765e00763262d518df8f4ec

See more details on using hashes here.

Supported by

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