python-ai-ragbot
python-ai-ragbot is a modular and framework-agnostic Python package for building intelligent chatbots and voicebots with Retrieval-Augmented Generation (RAG), powered by OpenAI and LangChain.
It provides a simple interface to attach ready-made request handlers into popular frameworks (FastAPI, Flask). You can quickly add both text chat (/chat) and voice (/voice) endpoints into your app. For other frameworks we are aggresively working to release the update
Features
- Supports knowledge sources:
- Local files (
.pdf,.docx,.txt,.md) - Website scraping (URLs, sitemaps)
- Local files (
/chatendpoint (text query → answer)/voiceendpoint (speech-to-text via Whisper, TTS for responses)- Fully configurable models, embeddings, voices, chunking, logging
- In-memory FAISS vector store via LangChain
- Adapters for:
- FastAPI
- Starlette
- Flask
- Django
- Raw WSGI
- Raw ASGI
- Sync (
init_rag_voice_bot) and Async (init_rag_voice_bot_async) APIs
Requirements
- Python 3.9+
- An OpenAI API key (
OPENAI_API_KEYin.env)
Installation
pip install python-ai-ragbot
For local development:
git clone https://github.com/your-org/python-ai-ragbot.git
cd python-ai-ragbot
pip install -e .
Quick Start (FastAPI)
# examples/server.py
from fastapi import FastAPI
from python_ai_ragbot import init_rag_voice_bot_async
from python_ai_ragbot.http.adapters import use_in_fastapi
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
import os
load_dotenv()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.on_event("startup")
async def startup_event():
bot = await init_rag_voice_bot_async({
"sources": {"files": ["examples/knowledge.txt"]},
"openai": {
"apiKey": os.getenv("OPENAI_API_KEY"),
"chat": {"model": "gpt-4o"},
"stt": {"model": "whisper-1"},
"tts": {"model": "tts-1-hd", "voice": "nova"},
}
})
use_in_fastapi(app, bot["chat_handler"], bot["voice_handler"], prefix="/api/bot")
Run:
uvicorn examples.server:app --reload --port 3001
Endpoints:
POST /api/bot/chatPOST /api/bot/voice
Usage with Other Frameworks
Flask
from flask import Flask
from python_ai_ragbot import init_rag_voice_bot
from python_ai_ragbot.http.adapters import use_in_flask
import os
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
bot = init_rag_voice_bot({
"sources": {"files": ["examples/knowledge.txt"]},
"openai": {"apiKey": os.getenv("OPENAI_API_KEY")},
})
use_in_flask(app, bot["chat_handler"], bot["voice_handler"], prefix="/api/bot")
if __name__ == "__main__":
app.run(port=3001)
Configuration
{
"sources": {
"files": ["knowledge.txt", "knowledge.pdf"],
"urls": ["https://docs.example.com"]
},
"rag": {
"textSplit": {"chunkSize": 1000, "chunkOverlap": 200},
"topK": 3
},
"openai": {
"apiKey": "...",
"embeddings": {"model": "text-embedding-3-small"},
"chat": {"model": "gpt-4o", "temperature": 0.3},
"stt": {"model": "whisper-1"},
"tts": {"model": "tts-1-hd", "voice": "nova"}
},
"logger": "console"
}
Endpoints
/chat
- POST JSON
{"question": "What is in the knowledge base?"}
/voice
- POST raw audio (
audio/webm,audio/wav, etc.)
Example Project Structure
my-app/
├── examples/
│ ├── server.py
│ ├── knowledge.txt
├── src/
│ └── python_ai_ragbot/
├── .env
└── pyproject.toml
Notes
- Use
init_rag_voice_bot_asyncin ASGI frameworks (FastAPI, Starlette). - Use
init_rag_voice_botin WSGI frameworks (Flask, Django, raw WSGI). - Vector store is in-memory only; data is reloaded on each startup.
Metadata
Release files for python-ai-ragbot 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 | |
|---|---|---|---|
| python_ai_ragbot-0.1.1.tar.gz | 14.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_ai_ragbot-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.7 kB
Release files / python_ai_ragbot-0.1.1.tar.gz
| Download URL | python_ai_ragbot-0.1.1.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49b831f74308a5b6f679fd9d307c36de8a8e32fe32b76000e546a7f3d9a83fd6
|
|
BLAKE2b-256 checksum How to use checksums |
d4ef53e78a27350d62398455f242316c29345e7134983b262613153f0673462f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / python_ai_ragbot-0.1.1-py3-none-any.whl
| Download URL | python_ai_ragbot-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e7aa477a2126f52a114d8f69f0d355aaefcdebb05e099859022de3e8677ea09
|
|
BLAKE2b-256 checksum How to use checksums |
69c635a728fd9c114a10c723ff68f5b5079cb5f207285a7da661988da333e337
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|