@zukhruf/retrieval 0.8.87 → 0.8.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -37
- package/dist/postgres/pgvector-embedding-retriever.d.ts +4 -3
- package/dist/postgres/pgvector-embedding-retriever.d.ts.map +1 -1
- package/dist/postgres/pgvector-embedding-retriever.js +5 -4
- package/dist/postgres/pgvector-embedding-retriever.js.map +1 -1
- package/dist/postgres/pgvector-keyword-retriever.d.ts +10 -7
- package/dist/postgres/pgvector-keyword-retriever.d.ts.map +1 -1
- package/dist/postgres/pgvector-keyword-retriever.js +6 -4
- package/dist/postgres/pgvector-keyword-retriever.js.map +1 -1
- package/dist/postgres/postgres-passage-store.d.ts +20 -1
- package/dist/postgres/postgres-passage-store.d.ts.map +1 -1
- package/dist/postgres/postgres-passage-store.js +32 -2
- package/dist/postgres/postgres-passage-store.js.map +1 -1
- package/dist/sqlite/sqlite-bm25-retriever.d.ts +4 -3
- package/dist/sqlite/sqlite-bm25-retriever.d.ts.map +1 -1
- package/dist/sqlite/sqlite-bm25-retriever.js +4 -2
- package/dist/sqlite/sqlite-bm25-retriever.js.map +1 -1
- package/dist/sqlite/sqlite-embedding-retriever.d.ts +4 -3
- package/dist/sqlite/sqlite-embedding-retriever.d.ts.map +1 -1
- package/dist/sqlite/sqlite-embedding-retriever.js +4 -2
- package/dist/sqlite/sqlite-embedding-retriever.js.map +1 -1
- package/dist/sqlite/sqlite-passage-store.d.ts +13 -1
- package/dist/sqlite/sqlite-passage-store.d.ts.map +1 -1
- package/dist/sqlite/sqlite-passage-store.js +20 -1
- package/dist/sqlite/sqlite-passage-store.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -20,15 +20,18 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
20
20
|
|
|
21
21
|
import { openai } from '@ai-sdk/openai';
|
|
22
22
|
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
SqliteEmbeddingRetriever,
|
|
25
|
+
SqlitePassageStore,
|
|
26
|
+
} from '@zukhruf/retrieval/sqlite';
|
|
24
27
|
import { install } from '@zukhruf/vectors/sqlite';
|
|
25
28
|
|
|
26
29
|
const database = new DatabaseSync('knowledge.db'); // elt wrote the passage contract here
|
|
27
30
|
install(database); // or load sqlite-vec: the SQL is the same
|
|
28
31
|
|
|
32
|
+
const store = new SqlitePassageStore({ database, passages: 'docs_passages' });
|
|
29
33
|
const retriever = new SqliteEmbeddingRetriever({
|
|
30
|
-
|
|
31
|
-
passages: 'docs_passages',
|
|
34
|
+
store,
|
|
32
35
|
vectors: 'docs_passage_vectors',
|
|
33
36
|
model: openai.embedding('text-embedding-3-small'),
|
|
34
37
|
});
|
|
@@ -37,20 +40,29 @@ const results = await retriever.retrieve('how do I rotate a key?');
|
|
|
37
40
|
// 10 scored passages, best first: { passage: { id, text, source, seq, start, end, metadata }, score }
|
|
38
41
|
```
|
|
39
42
|
|
|
43
|
+
The passage store is the root of the composition. It holds the connection and the passages, and on Postgres the schema of the contract. Each retriever and `ContextWindow` takes the store and only its own part: the vectors and the model, or the keyword index. So two retrievers of one search read one connection and one contract, as Haystack's retrievers take their `document_store`.
|
|
44
|
+
|
|
40
45
|
## Search passages by meaning
|
|
41
46
|
|
|
42
47
|
An embedding retriever embeds the query with its AI SDK model and sends one SQL query to the engine. The engine ranks the passages by cosine similarity: `vec_distance_cosine` on SQLite, pgvector's `<=>` on Postgres, `VECTOR_DISTANCE` or elt's `marts.<name>_nearest` on SQL Server ([ADR 0003](./docs/adr/0003-an-embedding-retriever-runs-the-vector-search-in-the-sql-of-its-engine-one-query-or-a-batch.md)). The score is `1 - cosine distance`.
|
|
43
48
|
|
|
44
49
|
```ts
|
|
45
50
|
// Planned API.
|
|
46
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
PgvectorEmbeddingRetriever,
|
|
53
|
+
PostgresPassageStore,
|
|
54
|
+
} from '@zukhruf/retrieval/postgres';
|
|
47
55
|
|
|
48
|
-
const
|
|
56
|
+
const store = new PostgresPassageStore({
|
|
49
57
|
session: {
|
|
50
58
|
query: (sql, parameters) => pool.query(sql, parameters).then((r) => r.rows),
|
|
51
59
|
},
|
|
60
|
+
schema: 'rag', // the search_path of the session finds the relations when absent
|
|
52
61
|
passages: 'docs_passages',
|
|
53
|
-
|
|
62
|
+
});
|
|
63
|
+
const retriever = new PgvectorEmbeddingRetriever({
|
|
64
|
+
store,
|
|
65
|
+
vectors: 'docs_passage_vectors', // rag.docs_passage_vectors
|
|
54
66
|
model,
|
|
55
67
|
});
|
|
56
68
|
|
|
@@ -71,8 +83,7 @@ A keyword retriever queries the keyword index that elt writes: FTS5 on SQLite, `
|
|
|
71
83
|
import { SqliteBM25Retriever } from '@zukhruf/retrieval/sqlite';
|
|
72
84
|
|
|
73
85
|
const keywords = new SqliteBM25Retriever({
|
|
74
|
-
|
|
75
|
-
passages: 'docs_passages',
|
|
86
|
+
store,
|
|
76
87
|
index: 'docs_passages_fts',
|
|
77
88
|
operator: 'OR', // the default is 'AND', the implicit operator of FTS5
|
|
78
89
|
});
|
|
@@ -80,17 +91,18 @@ const keywords = new SqliteBM25Retriever({
|
|
|
80
91
|
const results = await keywords.retrieve('rotate signing key');
|
|
81
92
|
```
|
|
82
93
|
|
|
83
|
-
On Postgres the query has to use the text search configuration of the index. `PgvectorKeywordRetriever` takes it
|
|
94
|
+
On Postgres the query has to use the text search configuration of the index. `PgvectorKeywordRetriever` takes it in the index value, `index: { column, configuration }`, `'english'` when absent, as Haystack's `language`, LlamaIndex's `text_search_config` and LangChain's `tsv_lang` do. The configuration is a parameter of the statement, never SQL.
|
|
84
95
|
|
|
85
96
|
```ts
|
|
86
97
|
// Planned API.
|
|
87
98
|
import { PgvectorKeywordRetriever } from '@zukhruf/retrieval/postgres';
|
|
88
99
|
|
|
89
100
|
const keywords = new PgvectorKeywordRetriever({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
store,
|
|
102
|
+
index: {
|
|
103
|
+
column: 'keywords', // GENERATED ALWAYS AS (to_tsvector('simple', text)) STORED
|
|
104
|
+
configuration: 'simple', // keeps stop words and does not stem
|
|
105
|
+
},
|
|
94
106
|
});
|
|
95
107
|
```
|
|
96
108
|
|
|
@@ -141,7 +153,6 @@ import {
|
|
|
141
153
|
Rerank,
|
|
142
154
|
SimilarityCutoff,
|
|
143
155
|
} from '@zukhruf/retrieval';
|
|
144
|
-
import { SqlitePassageStore } from '@zukhruf/retrieval/sqlite';
|
|
145
156
|
|
|
146
157
|
const search = new PostprocessingRetriever({
|
|
147
158
|
retriever: hybrid,
|
|
@@ -154,10 +165,7 @@ const search = new PostprocessingRetriever({
|
|
|
154
165
|
topK: 8,
|
|
155
166
|
}), // lambda 1 = relevance only
|
|
156
167
|
new Collapse({ field: 'source', size: 1 }), // one passage per source
|
|
157
|
-
new ContextWindow({
|
|
158
|
-
store: new SqlitePassageStore({ database, passages: 'docs_passages' }),
|
|
159
|
-
windowSize: 3,
|
|
160
|
-
}),
|
|
168
|
+
new ContextWindow({ store, windowSize: 3 }), // the store of the retrievers
|
|
161
169
|
new LongContextReorder(),
|
|
162
170
|
],
|
|
163
171
|
});
|
|
@@ -240,6 +248,7 @@ No consumer uses it yet. These moves are forced onto it after it ships.
|
|
|
240
248
|
| `ScoredPassage` | LlamaIndex `NodeWithScore`; .NET `VectorSearchResult<TRecord>{Record, Score}` ([vector search](https://learn.microsoft.com/en-us/dotnet/ai/vector-stores/vector-search)) |
|
|
241
249
|
| `Retriever.retrieve` | LlamaIndex `BaseRetriever.retrieve` ([base_retriever.py](https://raw.githubusercontent.com/run-llama/llama_index/main/llama-index-core/llama_index/core/base/base_retriever.py)); LangChain `BaseRetriever` ([retrievers/index.ts](https://raw.githubusercontent.com/langchain-ai/langchainjs/main/libs/langchain-core/src/retrievers/index.ts)); Semantic Kernel `ITextSearch` ([text search](https://learn.microsoft.com/en-us/semantic-kernel/concepts/text-search/text-search-abstractions)) |
|
|
242
250
|
| engine retrievers | Haystack's retrievers for each document store ([retrievers](https://docs.haystack.deepset.ai/docs/retrievers)) |
|
|
251
|
+
| passage store as the root | Haystack `PgvectorEmbeddingRetriever(document_store=...)` and `PgvectorKeywordRetriever(document_store=...)` over `PgvectorDocumentStore(schema_name, table_name, language)` ([embedding_retriever.py](https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/main/integrations/pgvector/src/haystack_integrations/components/retrievers/pgvector/embedding_retriever.py)); LlamaIndex `VectorStoreIndex.as_retriever()`; LangChain `VectorStore.asRetriever()` |
|
|
243
252
|
| `topK`, `includeVectors` | Haystack `top_k` = 10 ([document_store.py](https://raw.githubusercontent.com/deepset-ai/haystack/main/haystack/document_stores/in_memory/document_store.py)), `return_embedding`; Mastra `topK` = 10 ([pg](https://mastra.ai/reference/vectors/pg)); .NET `IncludeVectors` ([VectorSearchOptions](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.vectordata.vectorsearchoptions-1)) |
|
|
244
253
|
| `Filter` | Haystack filters ([metadata filtering](https://docs.haystack.deepset.ai/docs/metadata-filtering)); LlamaIndex `MetadataFilters` ([types.py](https://raw.githubusercontent.com/run-llama/llama_index/main/llama-index-core/llama_index/core/vector_stores/types.py)); Qdrant `filter` ([search](https://qdrant.tech/documentation/search/search/)) |
|
|
245
254
|
| `FusionRetriever` | LlamaIndex `QueryFusionRetriever` ([fusion_retriever.py](https://raw.githubusercontent.com/run-llama/llama_index/main/llama-index-core/llama_index/core/retrievers/fusion_retriever.py)); LangChain `EnsembleRetriever` ([ensemble.ts](https://raw.githubusercontent.com/langchain-ai/langchainjs/main/libs/langchain-classic/src/retrievers/ensemble.ts)); Elasticsearch `rrf` ([rrf retriever](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/retrievers/rrf-retriever)); Qdrant `prefetch` ([hybrid queries](https://qdrant.tech/documentation/concepts/hybrid-queries/)) |
|
|
@@ -403,22 +412,20 @@ class VectorMissingError extends Error {
|
|
|
403
412
|
// @zukhruf/retrieval/sqlite
|
|
404
413
|
class SqliteEmbeddingRetriever implements BatchRetriever {
|
|
405
414
|
constructor(options: {
|
|
406
|
-
|
|
407
|
-
passages: string;
|
|
415
|
+
store: SqlitePassageStore;
|
|
408
416
|
vectors: string;
|
|
409
417
|
model: EmbeddingModel;
|
|
410
418
|
});
|
|
411
419
|
}
|
|
412
420
|
class SqliteBM25Retriever implements Retriever {
|
|
413
421
|
constructor(options: {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
index: string;
|
|
422
|
+
store: SqlitePassageStore;
|
|
423
|
+
index: string; // the FTS5 table
|
|
417
424
|
operator?: 'AND' | 'OR';
|
|
418
425
|
}); // 'AND'
|
|
419
426
|
}
|
|
420
427
|
class SqlitePassageStore implements PassageStore {
|
|
421
|
-
constructor(options: { database: DatabaseSync; passages: string });
|
|
428
|
+
constructor(options: { database: DatabaseSync; passages: string }); // SQLite has no schema
|
|
422
429
|
}
|
|
423
430
|
|
|
424
431
|
// @zukhruf/retrieval/postgres
|
|
@@ -430,23 +437,24 @@ type PostgresSession = {
|
|
|
430
437
|
};
|
|
431
438
|
class PgvectorEmbeddingRetriever implements BatchRetriever {
|
|
432
439
|
constructor(options: {
|
|
433
|
-
|
|
434
|
-
passages: string;
|
|
440
|
+
store: PostgresPassageStore;
|
|
435
441
|
vectors: string;
|
|
436
442
|
model: EmbeddingModel;
|
|
437
443
|
});
|
|
438
444
|
}
|
|
439
445
|
class PgvectorKeywordRetriever implements Retriever {
|
|
440
446
|
constructor(options: {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
index: string;
|
|
447
|
+
store: PostgresPassageStore;
|
|
448
|
+
index: { column: string; configuration?: string }; // 'english'
|
|
444
449
|
operator?: 'AND' | 'OR';
|
|
445
|
-
|
|
446
|
-
}); // 'AND', 'english'
|
|
450
|
+
}); // 'AND'
|
|
447
451
|
}
|
|
448
452
|
class PostgresPassageStore implements PassageStore {
|
|
449
|
-
constructor(options: {
|
|
453
|
+
constructor(options: {
|
|
454
|
+
session: PostgresSession;
|
|
455
|
+
schema?: string; // the search_path of the session when absent
|
|
456
|
+
passages: string;
|
|
457
|
+
});
|
|
450
458
|
}
|
|
451
459
|
|
|
452
460
|
// @zukhruf/retrieval/sqlserver
|
|
@@ -458,22 +466,24 @@ type SqlServerSession = {
|
|
|
458
466
|
};
|
|
459
467
|
class SqlServerEmbeddingRetriever implements BatchRetriever {
|
|
460
468
|
constructor(options: {
|
|
461
|
-
|
|
462
|
-
passages: string;
|
|
469
|
+
store: SqlServerPassageStore;
|
|
463
470
|
vectors: string;
|
|
464
471
|
model: EmbeddingModel;
|
|
465
472
|
});
|
|
466
473
|
}
|
|
467
474
|
class SqlServerKeywordRetriever implements Retriever {
|
|
468
475
|
constructor(options: {
|
|
469
|
-
|
|
470
|
-
passages: string;
|
|
476
|
+
store: SqlServerPassageStore;
|
|
471
477
|
index: string;
|
|
472
478
|
operator?: 'AND' | 'OR';
|
|
473
479
|
});
|
|
474
480
|
}
|
|
475
481
|
class SqlServerPassageStore implements PassageStore {
|
|
476
|
-
constructor(options: {
|
|
482
|
+
constructor(options: {
|
|
483
|
+
session: SqlServerSession;
|
|
484
|
+
schema?: string;
|
|
485
|
+
passages: string;
|
|
486
|
+
});
|
|
477
487
|
}
|
|
478
488
|
```
|
|
479
489
|
|
|
@@ -2,7 +2,7 @@ import { type EmbeddingModel } from 'ai';
|
|
|
2
2
|
import type { BatchRetriever } from '../batch-retriever.ts';
|
|
3
3
|
import type { RetrieveOptions } from '../retrieve-options.ts';
|
|
4
4
|
import type { ScoredPassage } from '../scored-passage.ts';
|
|
5
|
-
import type
|
|
5
|
+
import { type PostgresPassageStore } from './postgres-passage-store.ts';
|
|
6
6
|
/**
|
|
7
7
|
* Ranks the passages by the cosine similarity of their vectors to the query,
|
|
8
8
|
* with pgvector's `<=>` in the SQL of Postgres (ADR 0003).
|
|
@@ -10,8 +10,9 @@ import type { PostgresSession } from './postgres-session.ts';
|
|
|
10
10
|
export declare class PgvectorEmbeddingRetriever implements BatchRetriever {
|
|
11
11
|
#private;
|
|
12
12
|
constructor(options: {
|
|
13
|
-
|
|
14
|
-
readonly
|
|
13
|
+
/** The store of the passages, whose session and schema the search uses. */
|
|
14
|
+
readonly store: PostgresPassageStore;
|
|
15
|
+
/** The passage vectors, in the schema of the store. */
|
|
15
16
|
readonly vectors: string;
|
|
16
17
|
readonly model: EmbeddingModel;
|
|
17
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgvector-embedding-retriever.d.ts","sourceRoot":"","sources":["../../src/postgres/pgvector-embedding-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,IAAI,CAAC;AAK3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"pgvector-embedding-retriever.d.ts","sourceRoot":"","sources":["../../src/postgres/pgvector-embedding-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,IAAI,CAAC;AAK3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,6BAA6B,CAAC;AAIrC;;;GAGG;AACH,qBAAa,0BAA2B,YAAW,cAAc;;IAM/D,YAAY,OAAO,EAAE;QACnB,2EAA2E;QAC3E,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;QACrC,uDAAuD;QACvD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;KAChC,EAMA;IAEK,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CAU1B;IAEK,YAAY,CAChB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAU5B;CA8FF"}
|
|
@@ -4,8 +4,8 @@ import { DimensionMismatchError } from '@zukhruf/vectors';
|
|
|
4
4
|
import { describe, modelName, parseModelIdentity, } from '../model-identity.js';
|
|
5
5
|
import { ModelMismatchError } from '../model-mismatch-error.js';
|
|
6
6
|
import { bind } from './bind.js';
|
|
7
|
-
import { identifier } from './identifier.js';
|
|
8
7
|
import { passage, passageJson } from './passage-row.js';
|
|
8
|
+
import { contractOf, } from './postgres-passage-store.js';
|
|
9
9
|
import { where } from './where.js';
|
|
10
10
|
/**
|
|
11
11
|
* Ranks the passages by the cosine similarity of their vectors to the query,
|
|
@@ -17,9 +17,10 @@ export class PgvectorEmbeddingRetriever {
|
|
|
17
17
|
#vectors;
|
|
18
18
|
#model;
|
|
19
19
|
constructor(options) {
|
|
20
|
-
|
|
21
|
-
this.#
|
|
22
|
-
this.#
|
|
20
|
+
const contract = contractOf(options.store);
|
|
21
|
+
this.#session = contract.session;
|
|
22
|
+
this.#passages = contract.passages;
|
|
23
|
+
this.#vectors = contract.relation(options.vectors);
|
|
23
24
|
this.#model = options.model;
|
|
24
25
|
}
|
|
25
26
|
async retrieve(query, options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgvector-embedding-retriever.js","sourceRoot":"","sources":["../../src/postgres/pgvector-embedding-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAE1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CAAC,SAAS;4BACzB,KAAK,QAAQ,MAAM;;gBAE/B,IAAI;;+CAE2B,EACzC,UAAU,CACX,CAAC;QACF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAoB,EAAE,CAAC,EAAE,CAAC,CAAC;QACrD,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;YACzB,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;gBAClC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAClC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBACpC,GAAG,CAAC,OAAO,CAAC,cAAc,KAAK,IAAI;oBACjC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE;oBAC3C,CAAC,CAAC,EAAE,CAAC;aACR,CAAC,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,SAAS,YAAY,CAAC,IAAa;IACjC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACzC,MAAM,IAAI,SAAS,CACjB,6CAA6C,MAAM,CAAC,IAAI,CAAC,EAAE,CAC5D,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RetrieveOptions } from '../retrieve-options.ts';
|
|
2
2
|
import type { Retriever } from '../retriever.ts';
|
|
3
3
|
import type { ScoredPassage } from '../scored-passage.ts';
|
|
4
|
-
import type
|
|
4
|
+
import { type PostgresPassageStore } from './postgres-passage-store.ts';
|
|
5
5
|
/**
|
|
6
6
|
* Ranks the passages by Postgres full-text search over the keyword index
|
|
7
7
|
* that elt writes: a `tsvector` column of the passages, `to_tsvector(configuration,
|
|
@@ -11,14 +11,17 @@ import type { PostgresSession } from './postgres-session.ts';
|
|
|
11
11
|
export declare class PgvectorKeywordRetriever implements Retriever {
|
|
12
12
|
#private;
|
|
13
13
|
constructor(options: {
|
|
14
|
-
|
|
15
|
-
readonly
|
|
16
|
-
/** The
|
|
17
|
-
readonly index:
|
|
14
|
+
/** The store of the passages, whose session and schema the search uses. */
|
|
15
|
+
readonly store: PostgresPassageStore;
|
|
16
|
+
/** The keyword index as elt writes it. */
|
|
17
|
+
readonly index: {
|
|
18
|
+
/** The `tsvector` column of the passages. */
|
|
19
|
+
readonly column: string;
|
|
20
|
+
/** The text search configuration that made the column, 'english' when absent. */
|
|
21
|
+
readonly configuration?: string;
|
|
22
|
+
};
|
|
18
23
|
/** How the words of the query join: 'AND', as `plainto_tsquery` joins them, when absent. */
|
|
19
24
|
readonly operator?: 'AND' | 'OR';
|
|
20
|
-
/** The text search configuration of the index, 'english' when absent. */
|
|
21
|
-
readonly configuration?: string;
|
|
22
25
|
});
|
|
23
26
|
retrieve(query: string, options?: RetrieveOptions): Promise<ScoredPassage[]>;
|
|
24
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgvector-keyword-retriever.d.ts","sourceRoot":"","sources":["../../src/postgres/pgvector-keyword-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"pgvector-keyword-retriever.d.ts","sourceRoot":"","sources":["../../src/postgres/pgvector-keyword-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,6BAA6B,CAAC;AAIrC;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,SAAS;;IAOxD,YAAY,OAAO,EAAE;QACnB,2EAA2E;QAC3E,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;QACrC,0CAA0C;QAC1C,QAAQ,CAAC,KAAK,EAAE;YACd,6CAA6C;YAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;YACxB,iFAAiF;YACjF,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;SACjC,CAAC;QACF,4FAA4F;QAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;KAClC,EAOA;IAEK,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CA+B1B;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bind } from './bind.js';
|
|
2
2
|
import { identifier } from './identifier.js';
|
|
3
3
|
import { passage, passageJson } from './passage-row.js';
|
|
4
|
+
import { contractOf, } from './postgres-passage-store.js';
|
|
4
5
|
import { where } from './where.js';
|
|
5
6
|
/**
|
|
6
7
|
* Ranks the passages by Postgres full-text search over the keyword index
|
|
@@ -15,11 +16,12 @@ export class PgvectorKeywordRetriever {
|
|
|
15
16
|
#operator;
|
|
16
17
|
#configuration;
|
|
17
18
|
constructor(options) {
|
|
18
|
-
|
|
19
|
-
this.#
|
|
20
|
-
this.#
|
|
19
|
+
const contract = contractOf(options.store);
|
|
20
|
+
this.#session = contract.session;
|
|
21
|
+
this.#passages = contract.passages;
|
|
22
|
+
this.#index = identifier(options.index.column);
|
|
21
23
|
this.#operator = options.operator ?? 'AND';
|
|
22
|
-
this.#configuration = options.configuration ?? 'english';
|
|
24
|
+
this.#configuration = options.index.configuration ?? 'english';
|
|
23
25
|
}
|
|
24
26
|
async retrieve(query, options = {}) {
|
|
25
27
|
options.abortSignal?.throwIfAborted();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgvector-keyword-retriever.js","sourceRoot":"","sources":["../../src/postgres/pgvector-keyword-retriever.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"pgvector-keyword-retriever.js","sourceRoot":"","sources":["../../src/postgres/pgvector-keyword-retriever.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAEL,UAAU,GACX,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAC1B,QAAQ,CAAkB;IAC1B,SAAS,CAAS;IAClB,MAAM,CAAS;IACf,SAAS,CAAe;IACxB,cAAc,CAAS;IAEhC,YAAY,OAYX;QACC,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,OAAO,CAA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S,yBAAyB,OAAO;gBAC3C,IAAI,CAAC,MAAM,qBAAqB,MAAM;;cAExC,IAAI,EAAE,EACd,UAAU,CACX,CAAC;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC1B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAClC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SAC9B,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import type { PassageStore } from '../passage-store.ts';
|
|
2
2
|
import type { Passage } from '../passage.ts';
|
|
3
3
|
import type { PostgresSession } from './postgres-session.ts';
|
|
4
|
-
/**
|
|
4
|
+
/** The connection and the relations of a PostgresPassageStore, which the Postgres retrievers read through it. */
|
|
5
|
+
export type PostgresContract = {
|
|
6
|
+
readonly session: PostgresSession;
|
|
7
|
+
/** The passages, qualified by the schema of the store when it has one. */
|
|
8
|
+
readonly passages: string;
|
|
9
|
+
/** Another relation of the contract, such as the passage vectors, qualified as the passages are. */
|
|
10
|
+
relation(name: string): string;
|
|
11
|
+
};
|
|
12
|
+
/** The connection and the relations of a store, so a retriever states neither again. Not exported from the package. */
|
|
13
|
+
export declare function contractOf(store: PostgresPassageStore): PostgresContract;
|
|
14
|
+
/**
|
|
15
|
+
* The passage contract in Postgres: the connection, the schema and the
|
|
16
|
+
* passages, which the Postgres retrievers and ContextWindow compose with, as
|
|
17
|
+
* Haystack's retrievers take its `PgvectorDocumentStore`. The schema
|
|
18
|
+
* qualifies every relation of the contract: the passages, the passage vectors
|
|
19
|
+
* and the keyword index. It reads passages by id, and the neighbours of a
|
|
20
|
+
* passage in its source.
|
|
21
|
+
*/
|
|
5
22
|
export declare class PostgresPassageStore implements PassageStore {
|
|
6
23
|
#private;
|
|
7
24
|
constructor(options: {
|
|
8
25
|
readonly session: PostgresSession;
|
|
26
|
+
/** The schema of the contract; the search_path of the session finds each relation when absent. */
|
|
27
|
+
readonly schema?: string;
|
|
9
28
|
readonly passages: string;
|
|
10
29
|
});
|
|
11
30
|
get(ids: readonly string[]): Promise<ReadonlyMap<string, Passage>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-passage-store.d.ts","sourceRoot":"","sources":["../../src/postgres/postgres-passage-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,
|
|
1
|
+
{"version":3,"file":"postgres-passage-store.d.ts","sourceRoot":"","sources":["../../src/postgres/postgres-passage-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,iHAAiH;AACjH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oGAAoG;IACpG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC,CAAC;AAUF,uHAAuH;AACvH,wBAAgB,UAAU,CAAC,KAAK,EAAE,oBAAoB,GAAG,gBAAgB,CAExE;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,YAAW,YAAY;;IAavD,YAAY,OAAO,EAAE;QACnB,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;QAClC,kGAAkG;QAClG,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,EAIA;IAQK,GAAG,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAcvE;IAED;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE;QACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAWrB;CACF"}
|
|
@@ -1,13 +1,43 @@
|
|
|
1
1
|
import { bind } from './bind.js';
|
|
2
2
|
import { identifier } from './identifier.js';
|
|
3
3
|
import { passage, passageJson } from './passage-row.js';
|
|
4
|
-
|
|
4
|
+
const bridge = {
|
|
5
|
+
contractOf: () => {
|
|
6
|
+
throw new Error('retrieval: the PostgresPassageStore class has not loaded');
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
/** The connection and the relations of a store, so a retriever states neither again. Not exported from the package. */
|
|
10
|
+
export function contractOf(store) {
|
|
11
|
+
return bridge.contractOf(store);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The passage contract in Postgres: the connection, the schema and the
|
|
15
|
+
* passages, which the Postgres retrievers and ContextWindow compose with, as
|
|
16
|
+
* Haystack's retrievers take its `PgvectorDocumentStore`. The schema
|
|
17
|
+
* qualifies every relation of the contract: the passages, the passage vectors
|
|
18
|
+
* and the keyword index. It reads passages by id, and the neighbours of a
|
|
19
|
+
* passage in its source.
|
|
20
|
+
*/
|
|
5
21
|
export class PostgresPassageStore {
|
|
6
22
|
#session;
|
|
23
|
+
#schema;
|
|
7
24
|
#passages;
|
|
25
|
+
static {
|
|
26
|
+
bridge.contractOf = (store) => ({
|
|
27
|
+
session: store.#session,
|
|
28
|
+
passages: store.#passages,
|
|
29
|
+
relation: (name) => store.#relation(name),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
8
32
|
constructor(options) {
|
|
9
33
|
this.#session = options.session;
|
|
10
|
-
this.#
|
|
34
|
+
this.#schema = options.schema;
|
|
35
|
+
this.#passages = this.#relation(options.passages);
|
|
36
|
+
}
|
|
37
|
+
#relation(name) {
|
|
38
|
+
return this.#schema === undefined
|
|
39
|
+
? identifier(name)
|
|
40
|
+
: `${identifier(this.#schema)}.${identifier(name)}`;
|
|
11
41
|
}
|
|
12
42
|
async get(ids) {
|
|
13
43
|
const parameters = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-passage-store.js","sourceRoot":"","sources":["../../src/postgres/postgres-passage-store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres-passage-store.js","sourceRoot":"","sources":["../../src/postgres/postgres-passage-store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAYxD,MAAM,MAAM,GAER;IACF,UAAU,EAAE,GAAG,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;CACF,CAAC;AAEF,uHAAuH;AACvH,MAAM,UAAU,UAAU,CAAC,KAA2B;IACpD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAoB;IACtB,QAAQ,CAAkB;IAC1B,OAAO,CAAqB;IAC5B,SAAS,CAAS;IAE3B;QACE,MAAM,CAAC,UAAU,GAAG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O,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,OAIhB;QACC,MAAM,UAAU,GAAc,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAChE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CACpC,UAAU,GAAG,sBAAsB,IAAI,CAAC,SAAS,yBAAyB,MAAM,wBAAwB,IAAI,QAAQ,EAAE,6CAA6C,EACnK,UAAU,CACX,CAAC;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DatabaseSync } from 'node:sqlite';
|
|
2
1
|
import type { RetrieveOptions } from '../retrieve-options.ts';
|
|
3
2
|
import type { Retriever } from '../retriever.ts';
|
|
4
3
|
import type { ScoredPassage } from '../scored-passage.ts';
|
|
4
|
+
import { type SqlitePassageStore } from './sqlite-passage-store.ts';
|
|
5
5
|
/**
|
|
6
6
|
* Ranks the passages by FTS5 `bm25()` over the keyword index that elt writes:
|
|
7
7
|
* an FTS5 table with the passages as its external content (ADR 0004). The
|
|
@@ -10,8 +10,9 @@ import type { ScoredPassage } from '../scored-passage.ts';
|
|
|
10
10
|
export declare class SqliteBM25Retriever implements Retriever {
|
|
11
11
|
#private;
|
|
12
12
|
constructor(options: {
|
|
13
|
-
|
|
14
|
-
readonly
|
|
13
|
+
/** The store of the passages, whose connection the search runs on. */
|
|
14
|
+
readonly store: SqlitePassageStore;
|
|
15
|
+
/** The FTS5 table over the passages, in the database of the store. */
|
|
15
16
|
readonly index: string;
|
|
16
17
|
/** How the words of the query join: 'AND', the implicit operator of FTS5, when absent. */
|
|
17
18
|
readonly operator?: 'AND' | 'OR';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-bm25-retriever.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-bm25-retriever.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite-bm25-retriever.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-bm25-retriever.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,KAAK,kBAAkB,EAAc,MAAM,2BAA2B,CAAC;AAGhF;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,SAAS;;IAMnD,YAAY,OAAO,EAAE;QACnB,sEAAsE;QACtE,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;QACnC,sEAAsE;QACtE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,0FAA0F;QAC1F,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;KAClC,EAMA;IAEK,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CAmB1B;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { identifier } from './identifier.js';
|
|
2
2
|
import { passageRows } from './passage-rows.js';
|
|
3
|
+
import { contractOf } from './sqlite-passage-store.js';
|
|
3
4
|
import { where } from './where.js';
|
|
4
5
|
/**
|
|
5
6
|
* Ranks the passages by FTS5 `bm25()` over the keyword index that elt writes:
|
|
@@ -12,8 +13,9 @@ export class SqliteBM25Retriever {
|
|
|
12
13
|
#index;
|
|
13
14
|
#operator;
|
|
14
15
|
constructor(options) {
|
|
15
|
-
|
|
16
|
-
this.#
|
|
16
|
+
const { database, passages } = contractOf(options.store);
|
|
17
|
+
this.#database = database;
|
|
18
|
+
this.#passages = passages;
|
|
17
19
|
this.#index = identifier(options.index);
|
|
18
20
|
this.#operator = options.operator ?? 'AND';
|
|
19
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-bm25-retriever.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-bm25-retriever.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IACrB,SAAS,CAAe;IACxB,SAAS,CAAS;IAClB,MAAM,CAAS;IACf,SAAS,CAAe;IAEjC,YAAY,
|
|
1
|
+
{"version":3,"file":"sqlite-bm25-retriever.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-bm25-retriever.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAA2B,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,mBAA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AAE;SACnB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;YACvC,OAAO;YACP,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;SACrB,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAE,QAAsB,EAAU,EAAE,CAC5E,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { DatabaseSync } from 'node:sqlite';
|
|
2
1
|
import { type EmbeddingModel } from 'ai';
|
|
3
2
|
import type { BatchRetriever } from '../batch-retriever.ts';
|
|
4
3
|
import type { RetrieveOptions } from '../retrieve-options.ts';
|
|
5
4
|
import type { ScoredPassage } from '../scored-passage.ts';
|
|
5
|
+
import { type SqlitePassageStore } from './sqlite-passage-store.ts';
|
|
6
6
|
/**
|
|
7
7
|
* Ranks the passages by the cosine similarity of their vectors to the query,
|
|
8
8
|
* with `vec_distance_cosine` in the SQL of SQLite (ADR 0003). The host
|
|
@@ -12,8 +12,9 @@ import type { ScoredPassage } from '../scored-passage.ts';
|
|
|
12
12
|
export declare class SqliteEmbeddingRetriever implements BatchRetriever {
|
|
13
13
|
#private;
|
|
14
14
|
constructor(options: {
|
|
15
|
-
|
|
16
|
-
readonly
|
|
15
|
+
/** The store of the passages, whose connection the search runs on. */
|
|
16
|
+
readonly store: SqlitePassageStore;
|
|
17
|
+
/** The passage vectors, in the database of the store. */
|
|
17
18
|
readonly vectors: string;
|
|
18
19
|
readonly model: EmbeddingModel;
|
|
19
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-embedding-retriever.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-embedding-retriever.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite-embedding-retriever.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-embedding-retriever.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,IAAI,CAAC;AAK3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,KAAK,kBAAkB,EAAc,MAAM,2BAA2B,CAAC;AAGhF;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,cAAc;;IAM7D,YAAY,OAAO,EAAE;QACnB,sEAAsE;QACtE,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;QACnC,yDAAyD;QACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;KAChC,EAMA;IAEK,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CAU1B;IAEK,YAAY,CAChB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAU5B;CA6FF"}
|
|
@@ -5,6 +5,7 @@ import { describe, modelName, parseModelIdentity, } from '../model-identity.js';
|
|
|
5
5
|
import { ModelMismatchError } from '../model-mismatch-error.js';
|
|
6
6
|
import { identifier } from './identifier.js';
|
|
7
7
|
import { passageRows } from './passage-rows.js';
|
|
8
|
+
import { contractOf } from './sqlite-passage-store.js';
|
|
8
9
|
import { where } from './where.js';
|
|
9
10
|
/**
|
|
10
11
|
* Ranks the passages by the cosine similarity of their vectors to the query,
|
|
@@ -18,8 +19,9 @@ export class SqliteEmbeddingRetriever {
|
|
|
18
19
|
#vectors;
|
|
19
20
|
#model;
|
|
20
21
|
constructor(options) {
|
|
21
|
-
|
|
22
|
-
this.#
|
|
22
|
+
const { database, passages } = contractOf(options.store);
|
|
23
|
+
this.#database = database;
|
|
24
|
+
this.#passages = passages;
|
|
23
25
|
this.#vectors = identifier(options.vectors);
|
|
24
26
|
this.#model = options.model;
|
|
25
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-embedding-retriever.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-embedding-retriever.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAEL,QAAQ,EACR,SAAS,EACT,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAC1B,SAAS,CAAe;IACxB,SAAS,CAAS;IAClB,QAAQ,CAAS;IACjB,MAAM,CAAiB;IAEhC,YAAY,
|
|
1
|
+
{"version":3,"file":"sqlite-embedding-retriever.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-embedding-retriever.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE3D,OAAO,E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CAAC,EAAE,CAAC;aACR,CAAC,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,SAAS,IAAI,CAAC,KAAc;IAC1B,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9C,MAAM,IAAI,SAAS,CACjB,oDAAoD,MAAM,CAAC,KAAK,CAAC,EAAE,CACpE,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import type { PassageStore } from '../passage-store.ts';
|
|
3
3
|
import type { Passage } from '../passage.ts';
|
|
4
|
-
/**
|
|
4
|
+
/** The connection and the passages of a SqlitePassageStore, which the SQLite retrievers read through it. */
|
|
5
|
+
export type SqliteContract = {
|
|
6
|
+
readonly database: DatabaseSync;
|
|
7
|
+
/** The passages as one SQLite identifier. */
|
|
8
|
+
readonly passages: string;
|
|
9
|
+
};
|
|
10
|
+
/** The connection and the passages of a store, so a retriever states neither again. Not exported from the package. */
|
|
11
|
+
export declare function contractOf(store: SqlitePassageStore): SqliteContract;
|
|
12
|
+
/**
|
|
13
|
+
* The passage contract in SQLite: the connection and the passages, which the
|
|
14
|
+
* SQLite retrievers and ContextWindow compose with. It reads passages by id,
|
|
15
|
+
* and the neighbours of a passage in its source.
|
|
16
|
+
*/
|
|
5
17
|
export declare class SqlitePassageStore implements PassageStore {
|
|
6
18
|
#private;
|
|
7
19
|
constructor(options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-passage-store.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-passage-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,
|
|
1
|
+
{"version":3,"file":"sqlite-passage-store.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-passage-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,4GAA4G;AAC5G,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAQF,sHAAsH;AACtH,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,cAAc,CAEpE;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,YAAY;;IAWrD,YAAY,OAAO,EAAE;QACnB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;QAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,EAGA;IAEK,GAAG,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAUvE;IAED;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE;QACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CASrB;CACF"}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { identifier } from './identifier.js';
|
|
2
2
|
import { passageRows } from './passage-rows.js';
|
|
3
|
-
|
|
3
|
+
const bridge = {
|
|
4
|
+
contractOf: () => {
|
|
5
|
+
throw new Error('retrieval: the SqlitePassageStore class has not loaded');
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
/** The connection and the passages of a store, so a retriever states neither again. Not exported from the package. */
|
|
9
|
+
export function contractOf(store) {
|
|
10
|
+
return bridge.contractOf(store);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The passage contract in SQLite: the connection and the passages, which the
|
|
14
|
+
* SQLite retrievers and ContextWindow compose with. It reads passages by id,
|
|
15
|
+
* and the neighbours of a passage in its source.
|
|
16
|
+
*/
|
|
4
17
|
export class SqlitePassageStore {
|
|
5
18
|
#database;
|
|
6
19
|
#passages;
|
|
20
|
+
static {
|
|
21
|
+
bridge.contractOf = (store) => ({
|
|
22
|
+
database: store.#database,
|
|
23
|
+
passages: store.#passages,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
7
26
|
constructor(options) {
|
|
8
27
|
this.#database = options.database;
|
|
9
28
|
this.#passages = identifier(options.passages);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-passage-store.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-passage-store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite-passage-store.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-passage-store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAShD,MAAM,MAAM,GAAkE;IAC5E,UAAU,EAAE,GAAG,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;CACF,CAAC;AAEF,sHAAsH;AACtH,MAAM,UAAU,UAAU,CAAC,KAAyB;IAClD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,k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+1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/retrieval",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.88",
|
|
4
4
|
"description": "The query side of RAG: retrievers that search a passage table by meaning or keywords in SQLite, Postgres or SQL Server, fuse lists, rerank and post-process, and give the best passages first with a score that is higher for a better passage.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -57,15 +57,15 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@zukhruf/statistics": "^0.8.
|
|
61
|
-
"@zukhruf/vectors": "^0.8.
|
|
60
|
+
"@zukhruf/statistics": "^0.8.88",
|
|
61
|
+
"@zukhruf/vectors": "^0.8.88",
|
|
62
62
|
"ai": "^7.0.179",
|
|
63
63
|
"pgvector": "^0.3.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/pg": "^8.23.1",
|
|
67
|
-
"@zukhruf/sqlite-open": "^0.8.
|
|
68
|
-
"@zukhruf/testing": "^0.8.
|
|
67
|
+
"@zukhruf/sqlite-open": "^0.8.88",
|
|
68
|
+
"@zukhruf/testing": "^0.8.88",
|
|
69
69
|
"pg": "^8.23.1"
|
|
70
70
|
}
|
|
71
71
|
}
|