SQL RAG & Code RAG
Structured databases and source repositories need retrieval strategies that preserve their structure rather than flattening everything into arbitrary text chunks.
type CodeHit = {
repository: string;
path: string;
symbol?: string;
startLine: number;
endLine: number;
};
SQL RAG
Retrieve schema/docs, generate a constrained query plan, enforce read-only/tenant policy and execute parameterized or validated SQL through deterministic code.
Code RAG
Index symbols, imports, call graphs, docs and file paths. Chunk at semantic boundaries such as functions/classes, then preserve repository/version metadata.
Practice
- Why should a model not execute arbitrary generated SQL directly?
- What metadata makes code retrieval useful for citations?
- Why are AST/symbol boundaries better than fixed chunks for many code tasks?
- How would you tenant-scope SQL RAG?