Implementation:AnswerDotAI RAGatouille RAGPretrainedModel From Index
| Knowledge Sources | |
|---|---|
| Domains | NLP, Information_Retrieval, Index_Management |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
Concrete tool for loading a ColBERT model and its associated PLAID index from an existing index directory provided by the RAGatouille library.
Description
The RAGPretrainedModel.from_index() class method restores a complete retrieval system from a previously built index. It creates a RAGPretrainedModel instance and initializes the underlying ColBERT object with load_from_index=True, which triggers loading the configuration from the index directory, restoring the PLAID model index, and deserializing the document collection and metadata mappings from disk.
Usage
Use this method when you have a previously built index and want to resume search or update operations without re-indexing. This is the standard entry point when deploying a search service or continuing work on an existing document collection.
Code Reference
Source Location
- Repository: RAGatouille
- File: ragatouille/RAGPretrainedModel.py
- Lines: L76-96
Signature
@classmethod
def from_index(
cls,
index_path: Union[str, Path],
n_gpu: int = -1,
verbose: int = 1,
) -> "RAGPretrainedModel":
"""Load an Index and the associated ColBERT encoder from an existing document index.
Parameters:
index_path (Union[str, Path]): Path to the index directory.
n_gpu (int): Number of GPUs to use. -1 means auto-detect.
verbose (int): Verbosity level. 1 filters most internal logs.
Returns:
RAGPretrainedModel: Initialized instance with model and index loaded.
"""
Import
from ragatouille import RAGPretrainedModel
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| index_path | Union[str, Path] | Yes | Path to an existing index directory built by RAGatouille |
| n_gpu | int | No | Number of GPUs to use. -1 (default) auto-detects available GPUs |
| verbose | int | No | Verbosity level. 1 (default) filters most internal ColBERT logs |
Outputs
| Name | Type | Description |
|---|---|---|
| return | RAGPretrainedModel | Initialized instance with self.model set to a ColBERT object. The model has its index loaded, collection restored, and pid_docid_map deserialized. |
Usage Examples
Load from a Previously Built Index
from ragatouille import RAGPretrainedModel
# Load model and index from disk
RAG = RAGPretrainedModel.from_index(".ragatouille/colbert/indexes/my_index")
# Immediately search without re-indexing
results = RAG.search("What is ColBERT?", k=5)
Load and Update an Existing Index
from ragatouille import RAGPretrainedModel
# Load existing index
RAG = RAGPretrainedModel.from_index(".ragatouille/colbert/indexes/my_index")
# Add new documents to the existing index
RAG.add_to_index(
new_collection=["New document text here."],
new_document_ids=["doc_new_1"],
)