Skip to main content

Advance hybrid rag imeplementation using Postgresql Vector DB

Project description

Alt text

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?

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

hector_rag-0.1.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hector_rag-0.1.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file hector_rag-0.1.1.tar.gz.

File metadata

  • Download URL: hector_rag-0.1.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.9 Darwin/24.3.0

File hashes

Hashes for hector_rag-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7bd6e597ce87acd14aedfbe880b4cd956898ab0b2b22a75be02c158931b86c70
MD5 a0ec0adf11f5aed80f24121a3145a193
BLAKE2b-256 8facbf8e87f867d0bef1b7b1de2e488a2b5cb48c49ec939bb0a7d9e6b9d5bc64

See more details on using hashes here.

File details

Details for the file hector_rag-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hector_rag-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.9 Darwin/24.3.0

File hashes

Hashes for hector_rag-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a709847fe34ae391352197f2847dd0ebf3dbf53977f65dcf842861fda61083ab
MD5 60a22d8d09059a4aef6ba34309df76ae
BLAKE2b-256 1fec8f9284654d638038f69a768625755167e5d683e2da298cc923716c381c6f

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