LeanCorpus

LeanCorpus is a full-text search library for .NET. It runs inside your application, keeps its index in immutable segment files on local disk, and has no runtime dependencies. It targets net10.0 and net11.0 and supports Native AOT.

dotnet add package LeanCorpus --version 4.0.0

Build your first search API reference Source on GitHub

using var dir = new MMapDirectory("./index");

using (var writer = new IndexWriter(dir, new IndexWriterConfig()))
{
    var doc = new LeanDocument();
    doc.Add(new StringField("id", "1"));
    doc.Add(new TextField("title", "The quick brown fox"));
    writer.AddDocument(doc);
    writer.Commit();
}

using var searcher = new IndexSearcher(dir);
var hits = searcher.Search(new TermQuery("title", "fox"), topN: 10);

Documentation preview: This branch describes the unreleased LeanCorpus 4.0.0 and Rowles.Text 2.0.0 package set. The NuGet badges below show published versions, which can differ from this source. Community Server is a separate alpha track.

Why LeanCorpus

Area What you get
Span-based analysis Ref-struct token pipeline designed to avoid per-token heap allocation during analysis.
Modern scoring BM25 (default), BM25+, BM25L, TF-IDF, Dirichlet, Jelinek-Mercer, and SIMD-accelerated cosine. Block-Max WAND for sublinear top-k.
Vector search built in Exact Float32 search for new vectors, with an opt-in Float32 vector graph for approximate candidate selection, exact search over historical decoded Int8 values, and read/search compatibility for historical BBQ. New Int8, BBQ and .hnsw writes are retired. Not a plugin.
Native AOT Trim-safe, publish-ready with PublishAot. Validated by a dedicated smoke-test suite.
LINQ queries IQueryable<T> provider translates expression trees to LeanCorpus queries.
Observability built in OpenTelemetry tracing and metrics, slow-query log, Aspire dashboard integration.
Performance evidence No release-qualified benchmark results are published for this preview. See the comparison and reproducibility guidance.

Start here

Start with this
Build your first search Create an index, add documents, and run a query in three short steps.
Choose a package Find the core library, standalone Rowles.Text, source generator and compression packages below.
Learn the architecture Understand documents, analysis, segments, readers, queries and vectors in Concepts.

Is LeanCorpus right for me?

Choose LeanCorpus when you need embedded, local .NET search with control over index files, query execution and Native AOT deployment. Choose Lucene.NET when its mature ecosystem and broad compatibility matter more than a modern .NET-first API. Choose Elasticsearch when you need a distributed service, operational tooling and multi-node scale. A database full-text feature is often simpler when search is secondary to transactional data and the required query behaviour is modest.

Feature tour

Analysis

Span-based analysis pipeline with tokenisers, 27 token filters, 3 character filters, stemmers for 10 languages (nine from Snowball 3.2.0), synonym graphs, Hunspell dictionary stemming, ICU, CJK tokenisation, pattern tokenisers and phonetic filters (Metaphone, Beider-Morse style). Browse analysis docs

More than 50 query types, including term, boolean, phrase, fuzzy (Myers bit-parallel), regexp (FST automaton), span, intervals, block-join, geo, and vector. Browse search docs

Scoring

BM25, BM25+, BM25L, TF-IDF (classic plus three variants), three language-model similarities, and SIMD cosine. Pluggable similarity API with expression-free function scoring. Browse scoring docs

Concurrency

Multi-threaded indexing with per-thread DWPT pools. Near-real-time readers via SearcherManager. Background merges that never block commits. Lease-protected segment caches. Browse concurrency docs

Observability

DefaultMetricsCollector, MeterMetricsCollector (System.Diagnostics.Metrics), OpenTelemetry tracing, structured slow-query log, Aspire dashboard integration. Browse observability docs

Extensibility

CodecKit for custom storage formats. Pluggable compression (LZ4, Snappy, Zstandard). Source-generated document schemas. Index codec migrator for format upgrades. Browse contributor docs

Packages

Package Repository version NuGet Description
LeanCorpus 4.0.0 NuGet Core library. Zero dependencies.
Rowles.Text 2.0.0 NuGet Standalone tokenisers, filters, stemmers and analysers.
LeanCorpus.SourceGen 1.1.0 NuGet Roslyn source generator for typed document mapping
LeanCorpus.Compression.LZ4 2.0.0 NuGet LZ4 stored-field compression
LeanCorpus.Compression.Snappy 2.0.0 NuGet Snappy stored-field compression
LeanCorpus.Compression.Zstandard 2.0.0 NuGet Zstandard stored-field compression

All packages target net10.0 and net11.0.


Build AOT Compatible Docs Quality Gate