Skip to main content

Query

RagPack has two query modes: semantic search, which returns ranked chunks, and RAG, which retrieves chunks and uses an LLM to produce a grounded answer. Both run hybrid search by default — a vector pass and a keyword/BM25 pass, fused server-side via weighted RRF (semantic-favored 7:3).

findSimilar embeds your query and returns the most relevant chunks from the collection, ranked by similarity score.

const results = await collection.findSimilar({
query: "how do I configure authentication?",
topK: 5,
});

for (const r of results) {
console.log(r.vector_similarity, r.chunk_text);
}
OptionTypeDescription
querystringNatural language search query
topKnumberNumber of results to return. Defaults to 5, max 100.
filtersFilterExpressionRestrict results to chunks whose document matches this filter expression
vectorSearchOnlybooleanSkip the keyword/BM25 pass and use pure vector search. Hybrid search runs by default.
hybridSettingsHybridSettingsPer-request override of the weighted RRF merge

Each result contains:

FieldTypeDescription
sourcestringDisplay name of the source document
chunk_textstring | nullThe matched text
chunk_headerstring | nullSection/heading breadcrumb the chunk was split under, if any
file_uristringSource document URI
mime_typestringMIME type of the source document
chunk_indexnumberPosition of this chunk within the document
extra_jsonstring | nullFreeform metadata attached at ingest time
metadataRecord<string, unknown> | undefinedTyped metadata field values registered for this collection
vector_distancenumberRaw vector distance. Lower is more similar.
vector_similaritynumberCosine similarity score (0–100). Higher is more relevant.
keyword_bm25_scorenumber | undefinedRaw BM25 score from the keyword channel; present only for hybrid results
rrf_scorenumber | undefinedRaw RRF fusion score; only comparable within this query's own weights/k; hybrid only
rrf_score_normalizednumber | undefinedRRF fusion score normalized so this batch's top result is 100; hybrid only

Response fields are returned exactly as the API sends them (snake_case), while request options use camelCase — the SDK converts for you.

Filtering by metadata

filters is a MongoDB-style expression compiled server-side into a predicate over a document's built-in (mime_type, source_name, file_uri, created_at, updated_at, …) and registered metadata fields.

await collection.findSimilar({
query: "refund policy",
filters: {
$and: [
{ mime_type: "application/pdf" },
{ $or: [{ tags: { $contains: "billing" } }, { created_at: { $gte: "7 days ago" } }] },
],
},
});

Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $like/$ilike (string fields), $contains/$containsAny/$containsAll (array fields), plus $and/$or for nesting.

Hybrid search tuning

Override the RRF merge for a single request with hybridSettings, or skip the keyword pass entirely with vectorSearchOnly:

const results = await collection.findSimilar({
query: "password reset",
vectorSearchOnly: false,
hybridSettings: {
semanticWeight: 0.7,
fullTextWeight: 0.3,
rrfK: 60,
fullTextLimit: 200,
},
});

RAG (retrieve + generate)

rag runs the full pipeline server-side: it retrieves the most relevant chunks, builds context, fills in your prompt template, and calls the configured LLM — returning both the answer and the chunks used to produce it.

const { answer, chunks } = await collection.rag({
query: "How do I reset my password?",
topK: 5,
promptSlug: "basic-rag",
model: "gpt-4o",
minSimilarity: 60,
});

console.log(answer);
OptionTypeDescription
querystringThe user's question
topKnumberNumber of chunks to retrieve. Defaults to 2, since RAG chunks feed an LLM prompt.
promptSlugstringSlug of the prompt template to use. Defaults to "basic_rag".
modelstringLLM model name (e.g. "gpt-4o", "llama3"). Falls back to server default if omitted.
minSimilaritynumberMinimum similarity score (0–100) a chunk must meet to be included. Omit to include all top-K results.
filtersFilterExpressionRestrict retrieval to chunks whose document matches this filter expression
vectorSearchOnlybooleanSkip the keyword/BM25 pass and use pure vector search. Hybrid search runs by default.
hybridSettingsHybridSettingsPer-request override of the weighted RRF merge

The response contains:

FieldTypeDescription
answerstringLLM-generated answer
chunksRagChunk[]Chunks used to build the context: source, file_uri, chunk_index, chunk_header, chunk_text, vector_similarity, plus keyword_bm25_score/rrf_score/rrf_score_normalized when hybrid ran. No mime_type, extra_json, metadata, or vector_distance — those are findSimilar-only.
formatted_promptstringThe fully expanded prompt sent to the LLM
prompt_slugstringThe prompt template used