Skip to main content

RAG Query

Query your knowledge base using semantic search. Returns relevant document chunks ranked by similarity.

Quick Method

const result = await jabrod.rag.query({
  kbId: 'kb_xxx',
  query: 'What is the refund policy?',
  topK: 5
});

console.log(result.chunks);
The builder pattern provides a fluent API for constructing queries:
const result = await jabrod.rag
  .queryBuilder()
  .withQuery('What is the refund policy?')
  .withKnowledgeBase('kb_xxx')
  .withTopK(5)
  .execute();

Builder Methods

MethodDescription
.withQuery(query)Set the search query (required)
.withKnowledgeBase(kbId)Set the knowledge base ID (required)
.withTopK(n)Number of results to return (default: 5)
.execute()Execute the query

Response Format

interface QueryResult {
  chunks: Array<{
    content: string;      // The matched text content
    score: number;        // Similarity score (0-1)
    documentId: string;   // Source document ID
    documentName: string; // Source document name
  }>;
}