Small-to-Big RAG implementation for more effective retrieval augmented generation
Project description
Small-to-Big RAG
A Python package implementing the Small-to-Big RAG approach for more effective retrieval augmented generation.
Installation
pip install small-to-big-rag
Usage
from small_to_big_rag import SmallToBigRAG
import os
# Initialize with Azure OpenAI credentials
rag = SmallToBigRAG(
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
api_version="2024-10-21",
embedding_model="text-embedding-3-small",
llm_model="gpt-4o-mini"
)
# Load a document
rag.load_file("path/to/document.txt")
# Or load text directly
text = """
Your document text here.
This can be multi-paragraph content.
The system will split this into paragraphs and sentences.
"""
rag.load_text(text)
# Generate a response
response = rag.generate_response(
query="What is the main topic of the document?",
system_prompt="You are a helpful assistant specialized in document analysis."
)
# Print the answer
print(response["answer"])
# Access source information
print("\nSources used:")
for i, sentence in enumerate(response["sources"]["sentences"]):
print(f"Sentence {i+1}: {sentence[:100]}...")
for i, paragraph in enumerate(response["sources"]["paragraphs"]):
print(f"Paragraph {i+1}: {paragraph[:100]}...")
Features
- Small-to-Big RAG approach that retrieves both sentences and their parent paragraphs
- Maintains relationships between sentences and paragraphs for better context
- Uses ChromaDB for vector storage and retrieval
- Supports Azure OpenAI API
- Easy-to-use Python API
Requirements
- Python 3.8+
- langchain-text-splitters
- openai
- chromadb
- python-dotenv
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file small_to_big_rag-0.1.0.tar.gz.
File metadata
- Download URL: small_to_big_rag-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8ff585e9902ff5a014a591f70c494d69282f15b41cca572d50ed3c267982a3d
|
|
| MD5 |
5512565d790a3ce7f34db5a4965e0524
|
|
| BLAKE2b-256 |
1daf1c2081722f2cdcf08f21ac9dd6c9de621a310ec453cc726896da124ac7e6
|
File details
Details for the file small_to_big_rag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: small_to_big_rag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2c7839aab388c45e9c735cb8b54cab210929113f4b365db8dabc144ce13c3f1
|
|
| MD5 |
1f518a6ca008be5af6a9d3a29734288d
|
|
| BLAKE2b-256 |
44d41113919f60270b9cb1f89395c744d880f4136b1358e76340bf2b4c6f38bc
|