Table of Contents

Property ContextWindow

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

ContextWindow

Gets or sets the number of neighboring partitions to include around each matched partition for contextual continuity.

public int ContextWindow { get; set; }

Property Value

int

A non-negative integer. Default is 0 (disabled).

Examples

LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
RagEngine ragEngine = new RagEngine(embeddingModel);

// Include 2 neighboring partitions on each side of every match
ragEngine.ContextWindow = 2;

// Disable context window expansion (the default)
ragEngine.ContextWindow = 0;

Remarks

When set to a positive value, each partition in the final retrieval results is expanded to include the specified number of preceding and following partitions from the same section. For example, a value of 1 includes one partition before and one after each match, while 2 includes two on each side.

Context partitions are included solely to provide surrounding text for the language model and receive a similarity score of 0. Partitions within the same section are emitted in sequential order. Overlapping windows from adjacent matches are merged automatically to avoid duplication.

Share