Skip to main content

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. You can download Neo4j from its official website: Neo4j Download Page For detailed installation instructions and additional resources, visit the Neo4j documentation page: Neo4j Documentation

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

Metadata

Release files for graph-vect-rag 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graph-vect-rag 1.0.1
File Size Uploaded
graph_vect_rag-1.0.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for graph-vect-rag 1.0.1
File Interpreter ABI Platform
graph_vect_rag-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / graph_vect_rag-1.0.1.tar.gz

Download URL graph_vect_rag-1.0.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1cd0bed453d22bf94f0a34c7c8df486139e2cef9426c66e4047f2c0c25efc3ad
BLAKE2b-256 checksum
How to use checksums
6c3d246bbe3792ff6536548c3bb58eaa53814f7f722bb75c8eb851cdf9984811
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / graph_vect_rag-1.0.1-py3-none-any.whl

Download URL graph_vect_rag-1.0.1-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57e1af3a32fdae125b0f1d3d8c12bcbb986e02633937be07d901bc438aea3885
BLAKE2b-256 checksum
How to use checksums
2e772f47d0128a9007ed5387dbdd3d32cb07c4bcb6a88450dca4698188b080e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page