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.
- 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.
To install Graph_Vect_RAG, use pip:
pip install graph-vect-ragfrom graph_rag_engine import Graph_RAG_Engine
engine = Graph_RAG_Engine()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
.envfile 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_KEYwhen theapi_keyargument 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".
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").
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
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"
)To load an existing knowledge base:
engine.load_knowledge_base(knowledge_base_name="my_knowledge_base")To query the loaded knowledge base using natural language:
response = engine.query_knowledge_base("What is the capital of France?")
print(response)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.
The following models are supported by the package:
llama-3.1-70b-versatilellama-3.1-8b-instantllama3-groq-70b-8192-tool-use-previewllama3-groq-8b-8192-tool-use-previewllama-guard-3-8bllama3-70b-8192llama3-8b-8192mixtral-8x7b-32768gemma-7b-itgemma2-9b-it