Constructor RagEngine
RagEngine(LM, IVectorStore)
Initializes a new instance of the RagEngine class with a single embedding model.
[Obsolete("Use RagEngine(IEmbedder textEmbedder, ...). Wrap a local model with new Embedder(model).")]
public RagEngine(LM embeddingModel, IVectorStore vectorStore = null)
Parameters
embeddingModelLMThe embedding model to use for generating vector embeddings.
vectorStoreIVectorStoreAn optional IVectorStore for persisting embeddings. If
null, an in-memory store is used.
Examples
LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
RagEngine ragEngine = new RagEngine(new Embedder(embeddingModel));
Console.WriteLine("RagEngine created successfully.");
Exceptions
- ArgumentNullException
Thrown if
embeddingModelisnull.
RagEngine(IEnumerable<LM>, IVectorStore)
Initializes a new instance of the RagEngine class with multiple embedding models.
[Obsolete("Use RagEngine(IEmbedder textEmbedder, IImageEmbedder imageEmbedder, ...). Wrap local models with new Embedder(model).")]
public RagEngine(IEnumerable<LM> embeddingModels, IVectorStore vectorStore = null)
Parameters
embeddingModelsIEnumerable<LM>A collection of embedding models to register. Must contain at least one model.
vectorStoreIVectorStoreAn optional IVectorStore for persisting embeddings. If
null, an in-memory store is used.
Examples
// Multimodal RAG with text and vision models
LM textModel = LM.LoadFromModelID("embeddinggemma-300m");
LM visionModel = LM.LoadFromModelID("nomic-embed-vision");
RagEngine ragEngine = new RagEngine(new Embedder(textModel), new Embedder(visionModel));
Remarks
Use this constructor for multimodal retrieval-augmented generation when you need both text-only and vision-enabled embedding models.
Important: All provided models must share the same embedding space (same dimension and coordinate system); otherwise, similarity lookups will produce invalid results.
Exceptions
- ArgumentNullException
Thrown if
embeddingModelsisnullor empty.- ArgumentException
Thrown if the embedding models have different embedding dimensions.
RagEngine(IEmbedder, IVectorStore)
Initializes a new instance of the RagEngine class using an IEmbedder, so any embedding provider (a local model, AWS, or a custom endpoint) can supply the text vectors.
public RagEngine(IEmbedder textEmbedder, IVectorStore vectorStore = null)
Parameters
textEmbedderIEmbedderThe embedder used to produce text and query vectors. Cannot be null.
vectorStoreIVectorStoreAn optional IVectorStore; an in-memory store is used when null.
Remarks
When textEmbedder is a local Embedder, its model is
reused for chunking and tokenization, and image embedding is enabled automatically if
the model supports it. A remote embedder can query an already-populated store, but
importing documents requires a local tokenizer; use
RagEngine(IEmbedder, LM, IVectorStore) to provide one.
Exceptions
- ArgumentNullException
Thrown when
textEmbedderis null.
RagEngine(IEmbedder, IImageEmbedder, IVectorStore)
Initializes a new instance of the RagEngine class with separate text and image embedders for multimodal retrieval.
public RagEngine(IEmbedder textEmbedder, IImageEmbedder imageEmbedder, IVectorStore vectorStore = null)
Parameters
textEmbedderIEmbedderThe embedder used to produce text and query vectors. Cannot be null.
imageEmbedderIImageEmbedderThe embedder used to produce image vectors. May be null for text-only use.
vectorStoreIVectorStoreAn optional IVectorStore; an in-memory store is used when null.
Exceptions
- ArgumentNullException
Thrown when
textEmbedderis null.- ArgumentException
Thrown when the two embedders report different embedding dimensions.
RagEngine(IEmbedder, LM, IVectorStore)
Initializes a new instance of the RagEngine class with a remote or custom
textEmbedder and an explicit local tokenizerModel
used for chunking and token batching during import.
public RagEngine(IEmbedder textEmbedder, LM tokenizerModel, IVectorStore vectorStore = null)
Parameters
textEmbedderIEmbedderThe embedder used to produce text and query vectors. Cannot be null.
tokenizerModelLMA local model whose tokenizer is used to chunk imported documents. Cannot be null.
vectorStoreIVectorStoreAn optional IVectorStore; an in-memory store is used when null.
Exceptions
- ArgumentNullException
Thrown when
textEmbedderortokenizerModelis null.