|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**customer-support-rag** is a production-ready RAG (Retrieval-Augmented Generation) system that serves API endpoints for a frontend to answer customer queries. It uses a knowledge base of FAQs, product docs, and help center articles as context, with Claude as the LLM and a pure Go TF-IDF engine for embeddings with an in-memory vector store for semantic search. |
| 8 | + |
| 9 | +- **Repository**: https://github.com/gyaan/knowledge-pipeline.git |
| 10 | +- **License**: MIT |
| 11 | +- **Language**: Go 1.25.6 (macOS ARM64) |
| 12 | +- **External dependencies**: None (pure standard library) |
| 13 | + |
| 14 | +## Build & Run Commands |
| 15 | + |
| 16 | +```bash |
| 17 | +go build ./... # build all packages |
| 18 | +go test ./... # run all tests |
| 19 | +go test -run TestName ./path/to/package # run a single test |
| 20 | +go vet ./... # static analysis |
| 21 | + |
| 22 | +# Dry-run ingestion (loads KB, chunks, builds TF-IDF, prints stats) |
| 23 | +go run cmd/ingest/main.go |
| 24 | + |
| 25 | +# Run the API server (ingests KB on startup, serves on :8080) |
| 26 | +go run cmd/server/main.go |
| 27 | +``` |
| 28 | + |
| 29 | +## Architecture |
| 30 | + |
| 31 | +``` |
| 32 | +Startup: Load docs → Split → Build TF-IDF vocab → Embed chunks → Store in vector DB |
| 33 | +Request: POST /api/chat → Embed query → Vector search → Build context → Claude LLM → Response |
| 34 | +``` |
| 35 | + |
| 36 | +### Entry Points |
| 37 | +- **cmd/ingest/** — Dry-run CLI: loads knowledge base, chunks, builds TF-IDF vocab, prints stats (no server) |
| 38 | +- **cmd/server/** — Ingests KB at startup, then serves HTTP API with graceful shutdown (SIGINT/SIGTERM) |
| 39 | + |
| 40 | +### Internal Packages (data flow order) |
| 41 | +1. **config/** — Loads .env: API key, server port, KB path, chunk settings, model, session TTL |
| 42 | +2. **documents/** — `loader.go` reads .txt files with category/filename metadata, skips empty; `splitter.go` chunks with overlap |
| 43 | +3. **embeddings/** — `client.go` defines `Embedder` interface; `server.go` implements pure Go TF-IDF engine |
| 44 | +4. **vectordb/** — `memory.go` in-memory store (no disk persistence); `search.go` cosine similarity |
| 45 | +5. **llm/** — `client.go` defines `LLMClient` interface; `claude.go` Anthropic client; `openai.go` OpenAI client |
| 46 | +6. **rag/** — `chain.go` orchestrates: query → embed → vector search → build prompt → call LLM → return |
| 47 | +7. **session/** — `manager.go` manages conversation history with configurable TTL, crypto/rand IDs, stoppable cleanup |
| 48 | +8. **api/** — `server.go` HTTP router with graceful shutdown; `handlers.go` defines ChatHandler + HealthHandler |
| 49 | + |
| 50 | +### Shared Types |
| 51 | +- **pkg/models/** — `types.go` defines shared structs (Document, ChatRequest/Response, Session, Claude/OpenAI API types) |
| 52 | + |
| 53 | +### API Endpoints |
| 54 | +- `POST /api/chat` — `{"query": "...", "session_id": "..."}` → `{"session_id": "...", "answer": "...", "sources": [...]}` |
| 55 | +- `GET /api/health` — `{"status": "healthy", "active_sessions": N, "documents": N}` |
| 56 | + |
| 57 | +### Knowledge Base (`knowledge_base/`) |
| 58 | +- **faq/** — general, billing, technical, account FAQs |
| 59 | +- **product_docs/** — getting started, features, API docs, integrations |
| 60 | +- **help_center/** — troubleshooting, best practices, tutorials |
| 61 | + |
| 62 | +## Environment Variables (.env) |
| 63 | + |
| 64 | +``` |
| 65 | +ANTHROPIC_API_KEY= # Claude API key (required when LLM_PROVIDER=anthropic) |
| 66 | +SERVER_PORT=8080 # HTTP server port |
| 67 | +KNOWLEDGE_BASE_PATH=./knowledge_base |
| 68 | +CHUNK_SIZE=500 |
| 69 | +CHUNK_OVERLAP=50 |
| 70 | +TOP_K=5 |
| 71 | +CLAUDE_MODEL=claude-sonnet-4-5-20250929 |
| 72 | +SESSION_TTL_HOURS=24 |
| 73 | +LLM_PROVIDER=anthropic # anthropic or openai |
| 74 | +OPENAI_API_KEY= # OpenAI API key (required when LLM_PROVIDER=openai) |
| 75 | +OPENAI_MODEL=gpt-4o # OpenAI model name |
| 76 | +``` |
| 77 | + |
| 78 | +## Conventions |
| 79 | +- Zero external dependencies — pure `net/http` + standard library only |
| 80 | +- In-memory vector store (no external DB, no disk persistence) |
| 81 | +- Pure Go TF-IDF embeddings (no Python, no external embedding service) |
| 82 | +- Standard Go project layout: `cmd/`, `internal/`, `pkg/` |
| 83 | +- Configuration via `.env` file (gitignored) |
| 84 | +- Graceful shutdown with signal handling |
0 commit comments