Ananke.Postgres
0.9.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Ananke.Postgres --version 0.9.2
NuGet\Install-Package Ananke.Postgres -Version 0.9.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ananke.Postgres" Version="0.9.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ananke.Postgres" Version="0.9.2" />
<PackageReference Include="Ananke.Postgres" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ananke.Postgres --version 0.9.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ananke.Postgres, 0.9.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ananke.Postgres@0.9.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ananke.Postgres&version=0.9.2
#tool nuget:?package=Ananke.Postgres&version=0.9.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Ananke.Postgres
PostgreSQL provider for Ananke: PostgresKnowledgeStore (IKnowledgeStore) and PostgresKnowledgeCatalog
(IKnowledgeCatalog), on pgvector for embedding search and Postgres full-text search for keywords. Experimental
(ANNKEEXP004).
Install
dotnet add package Ananke.Postgres
Needs Postgres with the pgvector extension available. Quickest way:
docker run -p 5432:5432 -e POSTGRES_PASSWORD=postgres pgvector/pgvector:pg17
Quick start
#pragma warning disable ANNKEEXP004
using Ananke.Orchestration.Knowledge;
using Ananke.Postgres;
using Npgsql;
await using var dataSource = NpgsqlDataSource.Create("Host=localhost;Username=postgres;Password=postgres");
var store = new PostgresKnowledgeStore(dataSource, embedder, new PostgresKnowledgeOptions { Table = "docs_chunks" });
await store.UpsertAsync([new KnowledgeDocument { Id = "0001#0", Text = "Core.Identity is built on OpenIddict" }]);
var dense = await store.SearchAsync("token server library");
var keywords = await store.SearchAsync("OpenIddict", new SearchOptions { Mode = SearchMode.Sparse });
var both = await store.SearchAsync("Which library is Core.Identity built on?", new SearchOptions { Mode = SearchMode.Hybrid });
- Search modes.
Denseranks by cosine distance (HNSW index).Sparsesearches a generatedtsvectorcolumn (GIN index) and ranks by BM25.Hybridfuses both by reciprocal rank. - Keyword search ranks by BM25 from the table's own counts. How many rows hold each lexeme, and the table's rows
and length, are kept in
<table>_lexemesby triggers on the table, so a word common in your documents counts little, in any language and with no stop list (k1 1.2, b 0.75, asInMemoryKnowledgeStore). Only rows holding a rare query term, one found in at mostRareTermShareof rows (5%), are scored; a query with no rare term requires all its terms. So what is the telemetry backend scores the rows holdingtelemetryorbackend, not every row holding the. The counts are over the whole table, not the rows a filter keeps. - Writes to one table run one at a time (a transaction-level advisory lock), so the counts stay right and two writes can't deadlock. Upsert writes a batch in one statement; the last document given for an id is kept.
- Dense search returns the rows asked, under a filter too. pgvector reads at most
hnsw.ef_searchcandidates from the HNSW index (40 by default) and applies the filter and the score threshold after. So each dense query (and the catalog'sDiscoverAsync, which leaves out superseded entries) runs in a transaction of its own withSET LOCAL hnsw.ef_searchraised to the rows asked (up to 1,000, pgvector's limit) and, on pgvector 0.8 or later,SET LOCAL hnsw.iterative_scan = strict_order, so a filtered scan reads on until it has the rows. The pgvector version is read once, when the store first uses its table. An iterative scan stops afterhnsw.max_scan_tuples(20,000 by default, a server setting); on an earlier pgvector a filter that keeps few rows can still return fewer than asked. - Metadata is
jsonb; aKnowledgeFiltermatches rows whose metadata contains every key and value given, and for each key inKnowledgeFilter.AnyOfany one of its values. - Lists by date in the query.
ListAsyncwith aKnowledgeDateOrdercasts the key's value totimestamptz, orders newest first and applies the lower bound and the limit in SQL; a row whose value isn't a date and time (pg_input_is_valid, PostgreSQL 16 or later) comes after the dated ones. Without an order it lists by id. - Deletes remove rows.
DeleteAsyncwith an empty filter empties the table. - One embedder per table. The table is stamped with the embedder's
Identityand vector length inananke_embedders; a store whose embedder differs is refused, naming both. - Created on first use: the
vectorextension, the table and its indexes, and<table>_lexemeswith its trigger function and triggers. The role needs the rights to create them, or they must already exist. A table made by an earlier version gets its lexeme counts, fromts_stat, the first time a store opens it; writers wait while they are filled.
Options
| Option | Default | What it does |
|---|---|---|
Table |
ananke_knowledge (ananke_catalog for the catalog) |
The table, optionally schema-qualified; lower-case letters, digits, underscores |
TextSearchConfiguration |
simple |
How keyword search reads text: simple keeps words as they are; english stems them |
RareTermShare |
0.05 | Keyword search scores only rows holding a query term found in at most this share of rows (rounded up to whole rows); with none, rows holding every term. 1 scores every row holding any term |
Dimensions |
from the embedder | The vectors' length, when the embedder's identity doesn't say |
HnswEfSearch |
40 | The least hnsw.ef_search for dense search; a search asking for more rows raises it to the rows asked, up to 1,000 |
HnswIterativeScan |
StrictOrder |
hnsw.iterative_scan for dense search on pgvector 0.8 or later: StrictOrder or Off |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Ananke.Abstractions (= 0.9.2)
- Ananke.Orchestration.Knowledge (= 0.9.2)
- Npgsql (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.