Table of Contents

Constructor RagEngine

Namespace
LMKit.Retrieval
Assembly
LM-Kit.NET.dll

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

embeddingModel LM

The embedding model to use for generating vector embeddings.

vectorStore IVectorStore

An 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 embeddingModel is null.

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

embeddingModels IEnumerable<LM>

A collection of embedding models to register. Must contain at least one model.

vectorStore IVectorStore

An 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 embeddingModels is null or 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

textEmbedder IEmbedder

The embedder used to produce text and query vectors. Cannot be null.

vectorStore IVectorStore

An 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 textEmbedder is 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

textEmbedder IEmbedder

The embedder used to produce text and query vectors. Cannot be null.

imageEmbedder IImageEmbedder

The embedder used to produce image vectors. May be null for text-only use.

vectorStore IVectorStore

An optional IVectorStore; an in-memory store is used when null.

Exceptions

ArgumentNullException

Thrown when textEmbedder is 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

textEmbedder IEmbedder

The embedder used to produce text and query vectors. Cannot be null.

tokenizerModel LM

A local model whose tokenizer is used to chunk imported documents. Cannot be null.

vectorStore IVectorStore

An optional IVectorStore; an in-memory store is used when null.

Exceptions

ArgumentNullException

Thrown when textEmbedder or tokenizerModel is null.

Share