Imported from davidcp90/raglab-ai4devs (
AGENTS.md). Install upstream withnpx skills add davidcp90/raglab-ai4devs. Copyright stays with the author.
Agent guidance (AGENTS.md)
Context for AI agents working in this repo: layout, key files, how to run things, and where to change behavior.
Project overview
- Goal: ReAct chatbot (Wikipedia + RAG) served by Flask, with embeddings stored in PostgreSQL (pgvector).
- Source of truth:
practica-raglab-ai4devs.ipynb— Paso 3 (RAG/embeddings) and Paso 4 (ReAct + Flask). - Secrets:
.env(gitignored); template is.env.example.
Layout
raglab/
├── .env.example # Env template (OPENAI_API_KEY, POSTGRES_*)
├── .env # Real secrets (do not commit)
├── docker-compose.yml # postgres (pgvector) + flask
├── Dockerfile # Flask app image
├── requirements.txt # Python deps
├── app/
│ ├── __init__.py
│ ├── app.py # Flask app, PGVector retriever, qa_chain, ReAct agent
│ ├── config.py # Env loading, DATABASE_URL, COLLECTION_NAME
│ └── templates/
│ └── index.html # Chat UI
├── static/
│ └── styles/
│ └── name.css # Optional overrides for UI
├── scripts/
│ └── upload_embeddings.py # Paso 3 → PGVector (docs, split, embed, store)
├── index.html # Reference copy (UI lives in app/templates/)
└── practica-raglab-ai4devs.ipynb # Original notebook
Key files
| File | Role |
|---|---|
app/app.py |
Entrypoint. Creates PGVector store, retriever, RAG chain (LCEL), Wikipedia + RAG tools, ReAct agent. Defines /, /health, POST /ask_bot. |
app/config.py |
Loads .env, exposes OPENAI_API_KEY, DATABASE_URL, COLLECTION_NAME. Builds DATABASE_URL from POSTGRES_* if not set. |
scripts/upload_embeddings.py |
Same docs/splitter/embeddings as notebook Paso 3; writes to PGVector with pre_delete_collection=True. |
docker-compose.yml |
postgres: pgvector/pgvector:pg16, healthcheck. flask: build from Dockerfile, env from .env, DATABASE_URL for postgres host. |
How to run
- Start stack:
docker compose up -d - Upload embeddings:
docker compose run --rm flask python scripts/upload_embeddings.py - Local Flask (with Postgres on host): set
DATABASE_URLorPOSTGRES_HOST=localhostin.env, thenpython -m app.app - Local upload: same env;
python scripts/upload_embeddings.py
Conventions
- Use libs already in the repo (see
requirements.txt). Preferlangchain_communityPGVector withpsycopg2-binaryunless switching tolangchain-postgres/psycopg3 is required. - Config and secrets: env only (
.env); no hardcoded API keys or DB URLs. - Vector collection name is shared:
raglab_docs(orPGVECTOR_COLLECTION_NAME). Upload script and Flask app must use the same name.
Where to change what
| Change | Location |
|---|---|
| RAG prompt, model, temperature | app/app.py (template, llm_rag, qa_chain) |
| ReAct tools, agent type, model | app/app.py (tools, llm_agent, initialize_agent) |
| Document set for RAG | scripts/upload_embeddings.py (DOCS, splitter params) |
| DB connection / collection name | app/config.py; .env for values |
| Chat UI | app/templates/index.html and static/ |
| Docker/Compose | docker-compose.yml, Dockerfile, requirements.txt |
Architecture (reminder)
- Upload:
upload_embeddings.py→ same docs as Paso 3 → split → OpenAI embeddings → PGVector (raglab_docs). - Runtime: Flask starts → PGVector store (same collection) → retriever → qa_chain (RAG) → Wikipedia + RAG tools → ReAct agent;
/ask_botrunsagent.run(msg).
Keep README and this file in sync when adding features or changing layout.