# RAG Implementation

> Implement robust Retrieval-Augmented Generation for ChromaDB and Postgres.

- Skill: `xiangteng007/rag-implementation` (Agent Skill)
- Install (CLI): `npx skillmds add xiangteng007/rag-implementation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/xiangteng007/rag-implementation/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: xiangteng007 (https://skillmd.com/u/xiangteng007)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/xiangteng007/rag-implementation

---


# RAG Implementation Guidelines

## Hybrid Search Strategy
- Pure vector search fails on precise terminology (e.g., specific steel grades or project IDs).
- **Mandatory Mix**: Always combine Dense Vector Search (ChromaDB) with Sparse Keyword Search (PostgreSQL + pg_trgm / BM25).

## Context Window Optimization
- **Chunking**: Break documents down by semantic boundaries (headers, paragraphs), not arbitrary character limits.
- **Reranking**: Use a lightweight Cross-Encoder model locally or via API to rerank the top 20 retrieved chunks down to the top 5 most relevant before feeding to the Agent prompt.
- **Metadata Filtering**: Always use structured filters (Date >= X, Source = Y) before performing exact k-NN vector distance matches to drastically improve speed.

