Skip to main content

Basicrag - Lightweight RAG Pipeline

basicrag is a simple yet powerful Python package for building Retrieval-Augmented Generation (RAG) pipelines. With just a few lines of code, you can load documents, generate embeddings, and query information using state-of-the-art LLMs.


🚀 Features

  • ✅ Multi-format support: PDF, DOCX, TXT, and URLs
  • ✅ Customizable chunking: Control chunk size and overlap
  • ✅ Multiple LLM providers: Groq, Gemini, OpenAI
  • ✅ Custom prompts: Bring your own prompt templates
  • ✅ Progress logging: Visual console feedback at each step

📦 Installation

pip install basicrag

⚡ Quick Start

from basicrag import RAGPipeline

# Initialize pipeline
rag = RAGPipeline(
    llm_provider="groq",
    llm_model="llama3-70b-8192",
    api_key="YOUR_API_KEY"
)

# Load and process data
rag.load_data("https://en.wikipedia.org/wiki/Large_language_model")
rag.fit()

# Query the document
response = rag.query("What are large language models?")
print(response)

⚙️ Configuration Options

Parameter Default Description
llm_provider "groq" LLM provider: "groq", "gemini", "openai"
llm_model "llama3-70b-8192" Model name
api_key None Provider API key
chunk_size 1000 Text chunk size in characters
chunk_overlap 100 Chunk overlap in characters
top_k 3 Number of chunks to retrieve for context
embedding_model "sentence-transformers/all-MiniLM-L6-v2" Sentence embedding model
custom_prompt None Custom prompt template

✏️ Custom Prompt Templates

Customize the prompt using {context} and {query} placeholders:

custom_prompt = """[INSTRUCTIONS]
Answer the question using ONLY the provided context. 
If unsure, respond "I don't know".

[CONTEXT]
{context}

[QUESTION]
{query}

[ANSWER]
"""

rag = RAGPipeline(
    chunk_size=500,
    chunk_overlap=50,
    top_k=5,
    llm_provider="gemini",
    llm_model="gemini-pro",
    api_key="YOUR_GEMINI_KEY",
    custom_prompt=custom_prompt
)

🤖 Supported Models

basicrag is compatible with any model available through supported providers like Groq, Gemini, and OpenAI, as long as the provider's API supports it.

Below are popular examples, but you're free to use any valid model name:

Groq

  • llama3-70b-8192
  • llama3-8b-8192
  • mixtral-8x7b-32768
  • gemma2-9b-it

Gemini

  • gemini-pro
  • gemini-1.5-pro-latest
  • gemini-1.0-pro

OpenAI

  • gpt-4-turbo
  • gpt-3.5-turbo
  • gpt-4o

Tip: You can specify any model string supported by your selected provider using the llm_model parameter in the RAGPipeline.


🔧 Advanced Usage

📁 Local File Processing

rag.load_data("research_paper.pdf")
rag.load_data("contract.docx")
rag.load_data("notes.txt")

📚 Multiple Documents

rag = RAGPipeline(...)

# Load multiple sources
rag.load_data("https://example.com/article")
rag.load_data("data/document1.pdf")
rag.load_data("data/notes.txt")

rag.fit()

🔄 Changing Embedding Model

rag = RAGPipeline(
    embedding_model="sentence-transformers/all-mpnet-base-v2",
    # other params...
)

🖥️ Command Line Interface (CLI)

basicrag includes a simple CLI for quick RAG queries:

basicrag query "What is the main topic?" \
  --file document.pdf \
  --provider groq \
  --model llama3-70b-8192 \
  --api-key YOUR_KEY

🛠 Troubleshooting

Common Issues

  • Missing dependencies

    pip install -r requirements.txt
    
  • API key not set Set it in code or in a .env file:

    GROQ_API_KEY=your_api_key
    GEMINI_API_KEY=your_api_key
    OPENAI_API_KEY=your_api_key
    
  • Unsupported file format Currently supported formats: .pdf, .docx, .txt, and URLs


🤝 Contributing

We welcome contributions! To set up your development environment:

  1. Clone the repo

  2. Create a virtual environment

  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Start coding!


📄 License

MIT License. See LICENSE for details.

Metadata

Release files for basicrag 0.1.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 basicrag 0.1.1
File Size Uploaded Provenance
basicrag-0.1.1.tar.gz 7.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for basicrag 0.1.1
File Interpreter ABI Platform
basicrag-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / basicrag-0.1.1.tar.gz

Download URL basicrag-0.1.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
88ffc68eccb81311c90b9fac089daecb03289b371a4670494c3f4125a0bbe3d0
BLAKE2b-256 checksum
How to use checksums
69329f061a59ee26ff4bfd59c0933562bc7583699d7061a1aee194c14e328bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.12

Release files / basicrag-0.1.1-py3-none-any.whl

Download URL basicrag-0.1.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b235062b3699668ee633831d476b073c7806b3ebd0162271b47bb8bd4916ee56
BLAKE2b-256 checksum
How to use checksums
4828a88ead90a3bee789a2bd84f4bd14351038838052a70da29f8943bc70dbaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.12

Security for basicrag 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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