Pipeline RAG
Ingiere documentos, genera embeddings y recupera contexto relevante durante el chat. Usa @agentskit/rag con cualquier embedder y almacén vectorial.
Configuración
import { createRAG } from '@agentskit/rag'
import { openaiEmbedder } from '@agentskit/adapters'
const rag = createRAG({
embed: openaiEmbedder({ apiKey: process.env.OPENAI_API_KEY! }),
store: yourVectorStore, // SQLite, Redis, or in-memory
chunkSize: 512,
chunkOverlap: 50,
})
Ingerir documentos
await rag.ingest([
{ id: 'readme', content: readFileSync('README.md', 'utf-8'), source: 'README.md' },
{ id: 'guide', content: readFileSync('docs/guide.md', 'utf-8'), source: 'guide.md' },
])
Buscar directamente
const results = await rag.search('how to configure tools', { topK: 3 })
results.forEach(doc => {
console.log(`[${doc.source}] ${doc.content.slice(0, 100)}...`)
})
Uso con chat
createRAG devuelve un Retriever: pásalo directamente a useChat o al runtime:
import { useChat } from '@agentskit/react'
function RAGChat() {
const chat = useChat({
adapter: yourAdapter,
retriever: rag, // retrieved context auto-injected into system prompt
})
// ... render chat UI
}
Fragmentación personalizada
const rag = createRAG({
embed: yourEmbedder,
store: yourStore,
split: (text) => text.split('\n\n'), // paragraph-based chunking
})