dcyfr.codes
beginnertypescript

Basic RAG Pipeline

Retrieve relevant context from a vector store, inject it into a prompt, and generate a grounded response.

Code

import { createRagPipeline } from '@dcyfr/ai-rag';

const rag = createRagPipeline({
  vectorStore: 'chroma',
  collection: 'dcyfr-docs',
  model: 'claude-sonnet-4-6',
  topK: 5,
  scoreThreshold: 0.7,
});

const response = await rag.query({
  question: 'How does the delegation framework handle TLP clearance?',
  systemPrompt: 'You are a helpful assistant. Answer based only on the provided context.',
});

console.log(response.answer);
console.log('Sources:', response.sources.map(s => s.title));

How it works

The `createRagPipeline` factory wires together embedding, retrieval, and generation. `scoreThreshold: 0.7` ensures only high-relevance chunks are included — lower values retrieve more context but increase noise.