Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:AnswerDotAI RAGatouille RAGPretrainedModel Search

From Leeroopedia
Knowledge Sources
Domains NLP, Information_Retrieval, Search
Last Updated 2026-02-12 12:00 GMT

Overview

Concrete tool for querying a PLAID index to retrieve the most relevant passages for a given query provided by the RAGatouille library.

Description

The RAGPretrainedModel.search() method queries a pre-built PLAID index. It delegates to ColBERT.search() which initializes a Searcher (lazily, on first call), converts optional document ID filters to passage IDs, and calls PLAIDModelIndex.search(). The searcher dynamically adjusts query token length and search parameters based on query and collection characteristics. Results are formatted with passage content, relevance scores, ranks, document IDs, passage IDs, and optional metadata.

The delegation chain is:

  • RAGPretrainedModel.search() → passes query and parameters
  • ColBERT.search() → manages searcher lifecycle, converts doc_ids to pids, formats results
  • PLAIDModelIndex.search() → manages Searcher initialization and configuration, dispatches single/batch search

Usage

Use this method after building an index with index() or loading one with from_index(). Supports single queries, batch queries, filtered search by document IDs, and fast search mode.

Code Reference

Source Location

  • Repository: RAGatouille
  • File: ragatouille/RAGPretrainedModel.py
  • Lines: L283-323

Signature

def search(
    self,
    query: Union[str, list[str]],
    index_name: Optional[str] = None,
    k: int = 10,
    force_fast: bool = False,
    zero_index_ranks: bool = False,
    doc_ids: Optional[list[str]] = None,
    **kwargs,
) -> Union[list[dict], list[list[dict]]]:
    """Query an index.

    Parameters:
        query: The query or list of queries to search for.
        index_name: Name of an index to query. If None, uses the current one.
        k: Number of results to return per query (default 10).
        force_fast: Use faster but less accurate search method.
        zero_index_ranks: Use zero-based ranking (default: rank 1 is highest).
        doc_ids: Optional list of document IDs to filter results.

    Returns:
        list[dict] or list[list[dict]]: Results with keys: content, score, rank,
        document_id, passage_id, and optionally document_metadata.
    """

Import

from ragatouille import RAGPretrainedModel

I/O Contract

Inputs

Name Type Required Description
query Union[str, list[str]] Yes Single query string or list of queries for batch search
index_name Optional[str] No Index name to query. Uses initialized index if None
k int No Number of top results per query (default 10)
force_fast bool No Enable faster but less accurate search (default False)
zero_index_ranks bool No Zero-based ranking instead of 1-based (default False)
doc_ids Optional[list[str]] No Filter results to specific document IDs

Outputs

Name Type Description
return (single query) list[dict] List of result dicts with keys: content, score, rank, document_id, passage_id, and optionally document_metadata
return (batch query) list[list[dict]] List of result lists, one per query

Usage Examples

Single Query Search

from ragatouille import RAGPretrainedModel

RAG = RAGPretrainedModel.from_index(".ragatouille/colbert/indexes/my_index")

results = RAG.search("What is ColBERT?", k=5)
for r in results:
    print(f"[{r['rank']}] (score: {r['score']:.4f}) {r['content'][:100]}")

Batch Query Search

queries = ["What is ColBERT?", "How does late interaction work?"]
batch_results = RAG.search(queries, k=3)

for i, query_results in enumerate(batch_results):
    print(f"Query {i}: {queries[i]}")
    for r in query_results:
        print(f"  [{r['rank']}] {r['content'][:80]}")

Filtered Search by Document IDs

# Only search within specific documents
results = RAG.search(
    "retrieval methods",
    k=5,
    doc_ids=["doc_1", "doc_3", "doc_7"],
)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment