Skip to main content

ragchatbot

PyPI version Python 3.10+ License: MIT

Add a semantic search chatbot to any website in minutes. Drop in your docs, get a working API, no ML experience required.

pip install ragchatbot
ragchatbot setup

Your chatbot API is live at http://localhost:8000.


What It Does

ragchatbot reads your documents, understands their meaning, and answers questions grounded in your actual content, not hallucinated responses.

Ask:

"what is your refund policy?"

and it finds the answer from your docs.


Requirements

  • Python 3.10 or higher
  • One of:

Quick Start

Step 1 — Install

pip install ragchatbot

Step 2 — Run guided setup

mkdir my-chatbot
cd my-chatbot
ragchatbot setup

Setup will:

  • Ask which LLM you want (Gemini, OpenAI, or Ollama)
  • Ask which model
  • Ask for your API key
  • Optionally protect your /ask endpoint with an API key
  • Create all folders
  • Scan and index your docs automatically

Step 3 — Add your docs

Put your .md, .txt, .pdf, or .docx files in the docs/ folder:

docs/
├── faq.md
├── refund-policy.pdf
├── shipping-policy.docx
└── terms.txt

Then press y when setup prompts you, it will index everything.

Step 4 — Ask a question

ragchatbot ask "what is your refund policy?"

Step 5 — Start the API server

ragchatbot start

API live at http://localhost:8000

Interactive API docs at http://localhost:8000/docs


Using the API

Browser-safe endpoint — /chat

If you're calling ragchatbot from a frontend (React, Vue, vanilla JS), use /chat instead of /ask. No API key needed in the browser.

const response = await fetch("http://localhost:8000/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ question: "What is your refund policy?" }),
});

Use /ask only from your own backend or CLI — it requires X-API-Key.

Once the server is running, your frontend can call it:

// Standard request
const response = await fetch("http://localhost:8000/ask", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "your-api-key", // only if auth is enabled
  },
  body: JSON.stringify({
    question: "What is your refund policy?",
  }),
});

const data = await response.json();
console.log(data.answer); // answer from your docs
console.log(data.sources); // ["refund-policy.pdf"]

Streaming responses

// Streaming request — tokens arrive as they're generated
const response = await fetch("http://localhost:8000/ask", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "your-api-key", // only if auth is enabled
  },
  body: JSON.stringify({
    question: "What is your refund policy?",
    stream: true,
  }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const chunk = decoder.decode(value);
  if (chunk.startsWith("\n\n__sources__:")) {
    const sources = JSON.parse(chunk.replace("\n\n__sources__:", ""));
    console.log("Sources:", sources);
  } else {
    process.stdout.write(chunk); // print tokens as they arrive
  }
}

Works with React, Vue, vanilla JS, Next.js — any frontend.


CLI Commands

ragchatbot setup                        # guided setup — LLM, API key, index docs
ragchatbot ask "your question"          # ask a question from terminal (streams by default)
ragchatbot ask "question" --no-stream   # wait for full answer
ragchatbot ask "question" --llm ollama  # ask using a specific LLM
ragchatbot start                        # index docs + start API server
ragchatbot start --port 9000            # use a different port
ragchatbot start --llm ollama           # start with a specific LLM
ragchatbot llm                          # show current LLM setup and switch if needed
ragchatbot stats                        # show what's indexed in ChromaDB
ragchatbot verify                       # re-check everything is working
ragchatbot init                         # scaffold folders + .env manually (advanced)
ragchatbot --help                       # show all commands

Auth on /ask

To protect your endpoint so only your frontend can use it:

ragchatbot setup  # choose "y" when asked about auth

Or add manually to .env:

RAGCHATBOT_API_KEY=your-secret-key

Then pass it in every request:

headers: { "X-API-Key": "your-secret-key" }

Without the key, the server returns 401 Unauthorized.


Using Ollama (Local, No API Key)

Ollama runs fully locally — no API key, no internet, no cost.

brew install ollama
ollama serve
ollama pull llama3.2

Then run setup and choose Ollama, or set in .env:

ragchatbot_LLM=ollama
ragchatbot_MODEL=llama3.2

Using OpenAI

pip install ragchatbot[openai]

Run setup and choose OpenAI, or set in .env:

OPENAI_API_KEY=your-openai-api-key
ragchatbot_LLM=openai
ragchatbot_MODEL=gpt-4o-mini

Supported File Types

Type Status
Markdown .md ✅ Supported
Plain text .txt ✅ Supported
PDF .pdf ✅ Supported
Word .docx ✅ Supported

Settings Reference

All settings live in .env (created automatically by ragchatbot setup):

Setting Default Description
GEMINI_API_KEY — Your Gemini API key
OPENAI_API_KEY — Your OpenAI API key
ragchatbot_DOCS ./docs Folder containing your docs
ragchatbot_DB ./chroma_db Where vectors are stored
ragchatbot_LLM gemini Which LLM: gemini, openai, or ollama
ragchatbot_MODEL per LLM default Model name — set automatically during setup
RAGCHATBOT_API_KEY — Protect /ask with this key (optional)
HF_HUB_OFFLINE 0 Set to 1 after first run to use cached embedding model

Links


License

MIT

Metadata

Release files for ragchatbot 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ragchatbot 1.1.3
File Size Uploaded Provenance
ragchatbot-1.1.3.tar.gz 24.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 48.5 kB

Release files / ragchatbot-1.1.3.tar.gz

Download URL ragchatbot-1.1.3.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ea182df9b0562163f7835566071584280462dbbf819224b50807099ec0302442
BLAKE2b-256 checksum
How to use checksums
5061c50c7e4618f29e15fdf91ec86c4c67b6c711379213894fc548d5a0c960ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / ragchatbot-1.1.3-py3-none-any.whl

Download URL ragchatbot-1.1.3-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4480dd906cd35fe290d52e4189d5846c8027f8649fe216f03294a5cb62368c4
BLAKE2b-256 checksum
How to use checksums
35dedca536d40a7775d2f0c91145e9225f00040e7827a4103021d2f2fcd20abb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Security for ragchatbot 1.1.3

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.

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