API reference · Kjarni 0.2.7
Class Searcher
Namespace: Kjarni
Assembly: Kjarni.dll
Document searcher for RAG applications.
public class Searcher : IDisposable
Inheritance
Implements
Examples
using var searcher = new Searcher(model: "minilm-l6-v2");
var results = searcher.Search("my_index", "What is machine learning?");
foreach (var r in results)
{
Console.WriteLine($"{r.Score:F4}: {r.Text[..50]}...");
}
Constructors
Searcher(string, string, string?, string?, SearchMode, int, bool)
Create a new Searcher.
public Searcher(string model = "minilm-l6-v2", string device = "cpu", string? cacheDir = null, string? rerankerModel = null, SearchMode defaultMode = SearchMode.Hybrid, int defaultTopK = 10, bool quiet = false)
Parameters
model string
Embedding model name (must match the model used to create the index)
device string
Compute device - "cpu" or "gpu"
cacheDir string?
Directory to cache downloaded models
rerankerModel string?
Optional cross-encoder model for reranking
defaultMode SearchMode
Default search mode
defaultTopK int
Default number of results
quiet bool
Suppress progress output
Properties
DefaultMode
Get the default search mode.
public SearchMode DefaultMode { get; }
Property Value
DefaultTopK
Get the default number of results.
public int DefaultTopK { get; }
Property Value
HasReranker
Check if a reranker is configured.
public bool HasReranker { get; }
Property Value
ModelName
Get the embedding model name used by this searcher.
public string ModelName { get; }
Property Value
RerankerModel
Get the reranker model name, or null if no reranker is configured.
public string? RerankerModel { get; }
Property Value
Methods
Dispose()
Releases the native model. The object cannot be used afterwards.
public void Dispose()
~Searcher()
Releases the native model if
protected ~Searcher()
Search(string, string, SearchMode?, int?, bool?, float?, string?, string?, string?)
Search an index.
public List<SearchResult> Search(string indexPath, string query, SearchMode? mode = null, int? topK = null, bool? rerank = null, float? threshold = null, string? sourcePattern = null, string? filterKey = null, string? filterValue = null)
Parameters
indexPath string
Path to the index directory
query string
Search query string
mode SearchMode?
Search mode (null = use default)
topK int?
Number of results (null = use default)
rerank bool?
Use reranker (null = auto)
threshold float?
Minimum score threshold
sourcePattern string?
Filter by source file pattern (glob)
filterKey string?
Metadata key to filter on
filterValue string?
Required value for filterKey
Returns
List of SearchResult objects
SearchKeywords(string, string, int)
Static keyword search (BM25) - no embedding model needed.
public static List<SearchResult> SearchKeywords(string indexPath, string query, int topK = 10)
Parameters
indexPath string
Path to the index directory
query string
Search query string
topK int
Maximum number of results
Returns
List of SearchResult objects
Kjarni runs the same engine on every platform: