Skip to content

Repository files navigation

TeD-RAG

Python RAG assistant for TED talks using an OpenAI-compatible API (LLMOD) + Pinecone. API ready; no front-end yet. Vercel serverless deployment included.

Prerequisites

  • Python 3.13+
  • Access to LLMOD/OpenAI-compatible API key and Pinecone credentials

Setup

  1. Create a virtual environment (if not already present):
    • Windows PowerShell: python -m venv .venv
  2. Activate the environment:
    • Windows PowerShell: .\.venv\Scripts\Activate
  3. Install runtime deps: .\.venv\Scripts\python -m pip install --upgrade pip && .\.venv\Scripts\python -m pip install -r requirements.txt (For notebooks/ingest tools, also install dev extras: .\.venv\Scripts\python -m pip install -r requirements.dev.txt)
  4. Copy .env.example to .env and fill LLMOD_API_KEY (or OPENAI_API_KEY), PINECONE_API_KEY, and Pinecone index settings.
  5. Register the Jupyter kernel (optional): .\.venv\Scripts\python -m ipykernel install --user --name ted-rag --display-name "Python (ted-rag)"
  6. (Optional) Launch Jupyter: jupyter lab or jupyter notebook

Environment variables

See .env.example for defaults:

  • LLMOD_API_KEY (or OPENAI_API_KEY)
  • LLMOD_BASE_URL (default https://api.llmod.ai/v1)
  • PINECONE_API_KEY
  • PINECONE_INDEX / PINECONE_INDEX_NAME (default ted-talks-index)
  • PINECONE_CLOUD / PINECONE_REGION
  • DATASET_PATH (default data/ted_talks_en.csv)
  • EMBEDDING_MODEL (default RPRTHPB-text-embedding-3-small)
  • CHAT_MODEL (default RPRTHPB-gpt-5-mini)
  • CHUNK_SIZE (<= 2048), OVERLAP_RATIO (<= 0.3), TOP_K (<= 30)

Project layout

  • src/settings.py — config and defaults
  • src/text_splitter.py — token-aware chunking
  • src/ingest.py — load CSV, chunk, embed, and upsert to Pinecone
  • src/server.py — FastAPI app with /api/prompt and /api/stats
  • .env.example — environment template
  • data/ — place ted_talks_en.csv here
  • requirements.txt — Python dependencies
  • .gitignore — ignores venv, caches, editor files

Usage

Ingest data

.\.venv\Scripts\python -m src.ingest --dataset data\ted_talks_en.csv --limit 200

Use --limit for cheap dry-runs; remove it to index all talks once satisfied.

Run the API locally

.\.venv\Scripts\python -m uvicorn src.server:app --reload --port 8000

Endpoints:

  • POST /api/prompt — ask a question; returns model response, retrieved context, and augmented prompt.
  • GET /api/stats — returns chunk_size, overlap_ratio, and top_k currently configured.

CLI query (no API server)

./.venv/Scripts/python main.py "Your question here" --top-k 8 --index-name ted-talks-index

Options: --top-k to override retrieval depth, --index-name to point at a specific Pinecone index, --region to override Pinecone region.

Deploy to Vercel

  • Add env vars in Vercel Dashboard: LLMOD_API_KEY (or OPENAI_API_KEY), LLMOD_BASE_URL (if different), PINECONE_API_KEY, PINECONE_INDEX_NAME (or PINECONE_INDEX), PINECONE_REGION (or PINECONE_ENVIRONMENT), plus optional EMBEDDING_MODEL, CHAT_MODEL, CHUNK_SIZE, OVERLAP_RATIO, TOP_K.
  • Ensure your Pinecone index dimension matches the embedding model (1536 for RPRTHPB-text-embedding-3-small).
  • The repo includes vercel.json and api/index.py (FastAPI + Mangum handler). Deploy with vercel CLI from the project root.
  • After deploy, call POST https://<your-deployment>/api/prompt with { "question": "..." } to query.

Notes for deployment

  • Pinecone index dim must match embedding model (1536 for text-embedding-3-small family).
  • Keep the index alive until grading is complete.
  • Vercel deployment: package this FastAPI app as a serverless function (or wrap via an ASGI adapter) and expose the same endpoints.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages