Hector RAG
A modular and extensible RAG (Retrieval Augmented Generation) package built on PostgreSQL vector database, offering advanced retrieval methods and fusion capabilities.
Key Features
- Multiple RAG retrieval methods:
- Similarity Search
- Keyword Search
- Graph Retrieval
- KAG (Knowledge-Aware Graph)
- Reciprocal Rank Fusion (RRF) for combining multiple retrieval methods
- Built on PostgreSQL vector database for efficient vector storage and retrieval
- Modular architecture allowing easy integration and customization
- Advanced RAG pipeline creation capabilities
Installation
Using pip:
pip install hector_rag
Using Poetry:
poetry add hector_rag
Requirements
- Python >=3.10,<3.13
- PostgreSQL database
- Dependencies:
- networkx
- semantic-router
- pgvector
- sqlalchemy
Quick Start
Basic Usage - Using 1 pg retriever
import os
from hector_rag import Hector
from hector_rag.retrievers import SimilarityRetriever, KeywordRetriever, GraphRetriever, RRFHybridRetriever
from hector_rag import Hector
from hector_rag.retrievers import GraphRetriever, SemanticRetriever, KeywordRetriever
semantic_retriever = SemanticRetriever(cursor,embeddings,embeddings_dimension=1536,collection_name=collection_name)
semantic_retriever.init_tables()
resp = semantic_retriever.get_relevant_documents(query="What is Fetch Ai ?", document_limit=10)
print(resp)
Advanced Usage
Combining Multiple Retrievers with RRF
import os
from hector_rag import Hector
from hector_rag.retrievers import SimilarityRetriever, KeywordRetriever, GraphRetriever, RRFHybridRetriever
from hector_rag import Hector
from hector_rag.retrievers import GraphRetriever, SemanticRetriever, KeywordRetriever
from langchain_openai.embeddings import OpenAIEmbeddings
from langchain_openai import ChatOpenAI
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
llm = ChatOpenAI(model="gpt-3.5-turbo")
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
collection_name = "new_collection_1"
rag = Hector(connection,embeddings, collection_name, {})
# Init all the retrievers that you want to use
semantic_retriever = SemanticRetriever()
graph_retriever = GraphRetriever(llm=llm)
keyword_retriever = KeywordRetriever()
# Add retrievers to Rag pipeline
rag.add_retriever(semantic_retriever)
rag.add_retriever(semantic_retriever)
rag.add_retriever(semantic_retriever)
# Fetch documents
docs = rag.get_relevant_documents("What is Decentralized AI ?", document_limit=10)
# Or directly use Hector Invoke to get llm response
while True:
query = str(input("Enter query: "))
response = rag.invoke(llm,query)
print(response)
Development
To set up the development environment:
# Clone the repository
git clone https://github.com/yourusername/hector-rag.git
cd hector-rag
# Install dependencies using Poetry
poetry install
Testing
poetry run pytest
Documentation
For detailed documentation about each retriever type and fusion methods, please visit our documentation page.
Contributing
Contributions are welcome! Whether it's:
- Adding new retrieval methods
- Improving existing retrievers
- Enhancing documentation
- Reporting bugs
- Suggesting features
Please feel free to submit a Pull Request or create an Issue.
License
MIT License
Contact
For issues and feature requests, please use the GitHub Issues page.
Would you like me to add or modify any specific section of this README?
Metadata
Release files for hector_rag 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hector_rag-0.1.1.tar.gz | 16.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hector_rag-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.6 kB
Release files / hector_rag-0.1.1.tar.gz
| Download URL | hector_rag-0.1.1.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bd6e597ce87acd14aedfbe880b4cd956898ab0b2b22a75be02c158931b86c70
|
|
BLAKE2b-256 checksum How to use checksums |
8facbf8e87f867d0bef1b7b1de2e488a2b5cb48c49ec939bb0a7d9e6b9d5bc64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.9 Darwin/24.3.0
|
Release files / hector_rag-0.1.1-py3-none-any.whl
| Download URL | hector_rag-0.1.1-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a709847fe34ae391352197f2847dd0ebf3dbf53977f65dcf842861fda61083ab
|
|
BLAKE2b-256 checksum How to use checksums |
1fec8f9284654d638038f69a768625755167e5d683e2da298cc923716c381c6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.9 Darwin/24.3.0
|