Скелет проекта

This commit is contained in:
2026-01-30 22:21:12 +03:00
commit 84ded7d7a9
30 changed files with 752 additions and 0 deletions

43
README.md Normal file
View File

@@ -0,0 +1,43 @@
# RAG Agent (Postgres)
Custom RAG agent that indexes text files from a git repository into Postgres
and answers queries using retrieval + LLM generation. Commits are tied to
**stories**; indexing and retrieval can be scoped by story.
## Quick start
1. Configure environment variables:
- `RAG_REPO_PATH` — path to git repo with text files
- `RAG_DB_DSN` — Postgres DSN (e.g. `postgresql://user:pass@localhost:5432/rag`)
- `RAG_EMBEDDINGS_DIM` — embedding vector dimension (e.g. `1536`)
2. Create DB schema:
- `python scripts/create_db.py` (or `psql "$RAG_DB_DSN" -f scripts/schema.sql`)
3. Index files for a story (e.g. branch name as story slug):
- `rag-agent index --story my-branch --changed --base-ref HEAD~1 --head-ref HEAD`
4. Ask a question (optionally scoped to a story):
- `rag-agent ask "What is covered?"`
- `rag-agent ask "What is covered?" --story my-branch`
## Git hook (index on commit)
Install the post-commit hook so changed files are indexed after each commit:
```bash
cp scripts/post-commit .git/hooks/post-commit && chmod +x .git/hooks/post-commit
```
Story for the commit is taken from (in order): env `RAG_STORY`, file `.rag-story` in repo root (one line = slug), or current branch name.
## DB structure
- **stories** — story slug (e.g. branch name); documents and chunks are tied to a story.
- **documents** — path + version per story; unique `(story_id, path)`.
- **chunks** — text chunks with embeddings (pgvector); updated when documents are re-indexed.
Scripts: `scripts/create_db.py` (Python, uses `ensure_schema` and `RAG_*` env), `scripts/schema.sql` (raw SQL).
## Notes
- The default embedding/LLM clients are stubs. Replace them in
`src/rag_agent/index/embeddings.py` and `src/rag_agent/agent/pipeline.py`.
- This project requires Postgres with the `pgvector` extension.