@duckedup/nidus 0.99.0 → 0.101.0
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 +46 -0
- package/dist/index.cjs +78 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -1
- package/dist/index.d.ts +101 -1
- package/dist/index.js +78 -4
- package/dist/index.js.map +1 -1
- package/dist/wasm/nidus_wasm.d.ts +3 -2
- package/dist/wasm/nidus_wasm.js +3 -2
- package/dist/wasm/nidus_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -33,18 +33,26 @@ interface NidusRecord {
|
|
|
33
33
|
id: string;
|
|
34
34
|
/** Omit for a text-only doc (indexed by FTS/metadata only, never by vector search). */
|
|
35
35
|
vector?: number[];
|
|
36
|
+
/**
|
|
37
|
+
* Named vectors beyond the reserved `"default"` vector above (nidus-85t), keyed by
|
|
38
|
+
* name. Each name must be declared on the collection first with
|
|
39
|
+
* {@link NidusClient.setVectorNames}, and every vector must be the store's dimension.
|
|
40
|
+
*/
|
|
41
|
+
vectors?: Record<string, number[]>;
|
|
36
42
|
attrs: Record<string, Value>;
|
|
37
43
|
}
|
|
38
44
|
/** Like {@link NidusRecord} but accepts plain JS values in `attrs` (auto-normalized). */
|
|
39
45
|
interface RecordInput {
|
|
40
46
|
id: string;
|
|
41
47
|
vector?: number[];
|
|
48
|
+
vectors?: Record<string, number[]>;
|
|
42
49
|
attrs: Record<string, AttrInput>;
|
|
43
50
|
}
|
|
44
51
|
/** A record read back from the server, with `attrs` decoded to plain JS values. */
|
|
45
52
|
interface DecodedRecord {
|
|
46
53
|
id: string;
|
|
47
54
|
vector?: number[];
|
|
55
|
+
vectors?: Record<string, number[]>;
|
|
48
56
|
attrs: Record<string, DecodedValue>;
|
|
49
57
|
}
|
|
50
58
|
/** A single attribute predicate, externally tagged as `nidus` encodes `Predicate`. */
|
|
@@ -355,6 +363,13 @@ interface OrderBy {
|
|
|
355
363
|
field: string;
|
|
356
364
|
descending?: boolean;
|
|
357
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* How several named-vector scores fold into one per-record score, before top-k
|
|
368
|
+
* selection (nidus-85t). `"Max"` (the default) takes the best weighted per-name score;
|
|
369
|
+
* an absent name then contributes nothing and carries no penalty. `"Sum"` adds every
|
|
370
|
+
* weighted named score. Meaningless when {@link SearchOptions.names} is empty.
|
|
371
|
+
*/
|
|
372
|
+
type Pool = "Max" | "Sum";
|
|
358
373
|
/** Ranking knobs shared by {@link NidusClient.search} and {@link NidusClient.textSearch}. */
|
|
359
374
|
interface RankingOptions {
|
|
360
375
|
rankBy?: RankBy;
|
|
@@ -429,6 +444,21 @@ interface SearchOptions extends ProjectionOptions, RankingOptions {
|
|
|
429
444
|
exact?: boolean;
|
|
430
445
|
/** See {@link RerankOptions}. `query` is required here. */
|
|
431
446
|
rerank?: RerankOptions;
|
|
447
|
+
/**
|
|
448
|
+
* Named vectors to score (nidus-85t), each declared on the collection first with
|
|
449
|
+
* {@link NidusClient.setVectorNames}. Omitted or empty (the default, and the only
|
|
450
|
+
* shape a pre-nidus-85t caller ever sends) searches only the reserved `"default"`
|
|
451
|
+
* vector, so an existing call is unaffected. A record is scored on whichever of
|
|
452
|
+
* these names it actually carries, reduced to one score by `pool`.
|
|
453
|
+
*/
|
|
454
|
+
names?: string[];
|
|
455
|
+
/**
|
|
456
|
+
* Per-name weight multiplying that name's score before pooling. A name absent here
|
|
457
|
+
* weights `1`. Meaningless when `names` is empty.
|
|
458
|
+
*/
|
|
459
|
+
nameWeights?: Record<string, number>;
|
|
460
|
+
/** How several named scores fold into one record score (default `"Max"`). See {@link Pool}. */
|
|
461
|
+
pool?: Pool;
|
|
432
462
|
}
|
|
433
463
|
/**
|
|
434
464
|
* Options for {@link NidusClient.searchSimilar}. `collection`/`id` name the source
|
|
@@ -587,6 +617,13 @@ interface HybridSearchBase extends AnnotationOptions {
|
|
|
587
617
|
expand?: Expand;
|
|
588
618
|
/** See {@link RerankOptions}. `query` is required here. */
|
|
589
619
|
rerank?: RerankOptions;
|
|
620
|
+
/**
|
|
621
|
+
* Cap the fused hits carrying any one value of an attribute (nidus-29ui). Applied on
|
|
622
|
+
* the shared cap → MMR → page-cut tail, same as {@link NidusClient.search}.
|
|
623
|
+
*/
|
|
624
|
+
limitPer?: LimitPer;
|
|
625
|
+
/** MMR lambda spreading the fused page in vector space (nidus-29ui). See {@link RankingOptions.diversity}. */
|
|
626
|
+
diversity?: number;
|
|
590
627
|
}
|
|
591
628
|
/** Options for {@link NidusClient.hybridSearch} (vector + BM25 fused via RRF). */
|
|
592
629
|
type HybridSearchOptions = HybridSearchBase & HybridQuerySpelling;
|
|
@@ -757,6 +794,47 @@ interface RecallOptions {
|
|
|
757
794
|
*/
|
|
758
795
|
rankBy?: RankBy;
|
|
759
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* One statement's answer from {@link NidusClient.query}: a ranked/listed statement decodes
|
|
799
|
+
* to a bare {@link Hit} array, or to `{hits, plan}` when it asked `WITH (plan)`; a `GROUP BY`
|
|
800
|
+
* statement decodes to an {@link Aggregation}.
|
|
801
|
+
*/
|
|
802
|
+
type QueryAnswer = Hit[] | {
|
|
803
|
+
hits: Hit[];
|
|
804
|
+
plan: QueryPlan;
|
|
805
|
+
} | Aggregation;
|
|
806
|
+
/**
|
|
807
|
+
* One compiled statement from {@link NidusClient.compile}: the typed value the SQL front end
|
|
808
|
+
* would hand the matching `Store` method (`search`/`text_search`/`hybrid_search`/`list`/
|
|
809
|
+
* `aggregate`), rendered for introspection only. `opts` (and, for `text_search`/`hybrid`,
|
|
810
|
+
* `query`/`text`) are the server's raw snake_case JSON — never executed, so never decoded
|
|
811
|
+
* into this SDK's own camelCase option shapes.
|
|
812
|
+
*/
|
|
813
|
+
type Compiled = {
|
|
814
|
+
kind: "search";
|
|
815
|
+
collections: string[];
|
|
816
|
+
vector: number[];
|
|
817
|
+
opts: Record<string, unknown>;
|
|
818
|
+
} | {
|
|
819
|
+
kind: "text_search";
|
|
820
|
+
collections: string[];
|
|
821
|
+
query: unknown;
|
|
822
|
+
opts: Record<string, unknown>;
|
|
823
|
+
} | {
|
|
824
|
+
kind: "hybrid";
|
|
825
|
+
collections: string[];
|
|
826
|
+
vector: number[];
|
|
827
|
+
text: unknown;
|
|
828
|
+
opts: Record<string, unknown>;
|
|
829
|
+
} | {
|
|
830
|
+
kind: "list";
|
|
831
|
+
collections: string[];
|
|
832
|
+
opts: Record<string, unknown>;
|
|
833
|
+
} | {
|
|
834
|
+
kind: "aggregate";
|
|
835
|
+
collections: string[];
|
|
836
|
+
opts: Record<string, unknown>;
|
|
837
|
+
};
|
|
760
838
|
|
|
761
839
|
/** Minimal `fetch` signature the client needs — satisfied by the platform global. */
|
|
762
840
|
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
@@ -839,6 +917,12 @@ declare class NidusClient {
|
|
|
839
917
|
* paid at write time and in memory. Pass an empty array to drop the declaration.
|
|
840
918
|
*/
|
|
841
919
|
setFilterIndex(name: string, fields: (string | FilterIndexField)[]): Promise<void>;
|
|
920
|
+
/**
|
|
921
|
+
* Declare the named-vector fields a collection accepts on upsert and search, beyond
|
|
922
|
+
* the reserved `"default"` vector (nidus-85t). Upserting an undeclared name is a
|
|
923
|
+
* `400` naming it; mirrors {@link NidusClient.setFtsSchema}'s declare-then-use shape.
|
|
924
|
+
*/
|
|
925
|
+
setVectorNames(name: string, names: string[]): Promise<void>;
|
|
842
926
|
/** Vector (cosine) nearest-neighbour search. Empty `scope` searches all collections. */
|
|
843
927
|
search(opts: SearchOptions): Promise<Hit[]>;
|
|
844
928
|
/** Like {@link NidusClient.search}, but also reports the scan strategy the server took. */
|
|
@@ -892,6 +976,22 @@ declare class NidusClient {
|
|
|
892
976
|
* in-RAM index alone — no record is built and no vector is read.
|
|
893
977
|
*/
|
|
894
978
|
aggregate(opts?: AggregateOptions): Promise<Aggregation>;
|
|
979
|
+
/**
|
|
980
|
+
* Compile and run a `SELECT ...` script against `POST /query` (SPEC §7.12). A single
|
|
981
|
+
* statement decodes to its own answer (hits, `{hits, plan}`, or an {@link Aggregation});
|
|
982
|
+
* a `;`-separated script answers one {@link QueryAnswer} per statement, in request order.
|
|
983
|
+
* A parse error rejects with the server's message verbatim (byte offset and §7 section).
|
|
984
|
+
*/
|
|
985
|
+
query(sql: string): Promise<QueryAnswer | QueryAnswer[]>;
|
|
986
|
+
/**
|
|
987
|
+
* Compile a `SELECT ...` script without running it: the typed value(s) the matching
|
|
988
|
+
* `Store` method would receive. Always an array, one entry per `;`-separated statement.
|
|
989
|
+
*/
|
|
990
|
+
compile(sql: string): Promise<Compiled[]>;
|
|
991
|
+
/** A wire hit's shape, distinguishing a bare hits-answer from a batch of answers. */
|
|
992
|
+
private isHitShaped;
|
|
993
|
+
/** Decode one statement's `/query` answer: hits (bare or `{hits, plan}`), or an aggregation. */
|
|
994
|
+
private decodeQueryAnswer;
|
|
895
995
|
/**
|
|
896
996
|
* Answer several vector queries in one round-trip (16 max). Returns one ranking per
|
|
897
997
|
* query in request order, or — with `opts.fuse` — a single array holding the one fused
|
|
@@ -1052,4 +1152,4 @@ declare function decodeValue(value: Value): DecodedValue;
|
|
|
1052
1152
|
/** Decode a whole wire `attrs` map back to plain JS values. */
|
|
1053
1153
|
declare function decodeAttrs(attrs: Record<string, Value>): Record<string, DecodedValue>;
|
|
1054
1154
|
|
|
1055
|
-
export { type AggregateOptions, type Aggregation, type AnnInfo, type AnnotationOptions, type Annotations, type AttrInput, type ClauseScore, type ClusterStatus, type CodeFileHit, type CodeSearchOptions, type CodeSymbolHit, type Decay, type DecodedRecord, type DecodedValue, type Expand, type Expansion, type FetchLike, type Filter, type FilterIndexField, type Footprint, type Fragment, type FtsCombine, type FtsField, type Highlight, type HighlightOptions, type Hit, type HybridQuerySpelling, type HybridSearchBase, type HybridSearchOptions, type LegScore, type LimitPer, type ListOptions, NidusClient, type NidusClientOptions, NidusError, type NidusRecord, type OrderBy, type PlanCandidates, type PlanNarrowing, type PlanTimings, type Predicate, type ProjectionOptions, type QueryPath, type QueryPlan, type RankBy, type RankingOptions, type Readiness, type RecallOptions, type RecordInput, type RememberOptions, type RememberResult, type RerankOptions, type Rollup, type SearchOptions, type SimilarSearchOptions, type Stats, type StoreVersions, type SuggestOptions, type Suggestion, type Suggestions, type TextClause, type TextQuerySpelling, type TextSearchBase, type TextSearchOptions, type Value, decodeAttrs, decodeValue, encodeAttrs, encodeValue, f, v };
|
|
1155
|
+
export { type AggregateOptions, type Aggregation, type AnnInfo, type AnnotationOptions, type Annotations, type AttrInput, type ClauseScore, type ClusterStatus, type CodeFileHit, type CodeSearchOptions, type CodeSymbolHit, type Compiled, type Decay, type DecodedRecord, type DecodedValue, type Expand, type Expansion, type FetchLike, type Filter, type FilterIndexField, type Footprint, type Fragment, type FtsCombine, type FtsField, type Highlight, type HighlightOptions, type Hit, type HybridQuerySpelling, type HybridSearchBase, type HybridSearchOptions, type LegScore, type LimitPer, type ListOptions, NidusClient, type NidusClientOptions, NidusError, type NidusRecord, type OrderBy, type PlanCandidates, type PlanNarrowing, type PlanTimings, type Predicate, type ProjectionOptions, type QueryAnswer, type QueryPath, type QueryPlan, type RankBy, type RankingOptions, type Readiness, type RecallOptions, type RecordInput, type RememberOptions, type RememberResult, type RerankOptions, type Rollup, type SearchOptions, type SimilarSearchOptions, type Stats, type StoreVersions, type SuggestOptions, type Suggestion, type Suggestions, type TextClause, type TextQuerySpelling, type TextSearchBase, type TextSearchOptions, type Value, decodeAttrs, decodeValue, encodeAttrs, encodeValue, f, v };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,18 +33,26 @@ interface NidusRecord {
|
|
|
33
33
|
id: string;
|
|
34
34
|
/** Omit for a text-only doc (indexed by FTS/metadata only, never by vector search). */
|
|
35
35
|
vector?: number[];
|
|
36
|
+
/**
|
|
37
|
+
* Named vectors beyond the reserved `"default"` vector above (nidus-85t), keyed by
|
|
38
|
+
* name. Each name must be declared on the collection first with
|
|
39
|
+
* {@link NidusClient.setVectorNames}, and every vector must be the store's dimension.
|
|
40
|
+
*/
|
|
41
|
+
vectors?: Record<string, number[]>;
|
|
36
42
|
attrs: Record<string, Value>;
|
|
37
43
|
}
|
|
38
44
|
/** Like {@link NidusRecord} but accepts plain JS values in `attrs` (auto-normalized). */
|
|
39
45
|
interface RecordInput {
|
|
40
46
|
id: string;
|
|
41
47
|
vector?: number[];
|
|
48
|
+
vectors?: Record<string, number[]>;
|
|
42
49
|
attrs: Record<string, AttrInput>;
|
|
43
50
|
}
|
|
44
51
|
/** A record read back from the server, with `attrs` decoded to plain JS values. */
|
|
45
52
|
interface DecodedRecord {
|
|
46
53
|
id: string;
|
|
47
54
|
vector?: number[];
|
|
55
|
+
vectors?: Record<string, number[]>;
|
|
48
56
|
attrs: Record<string, DecodedValue>;
|
|
49
57
|
}
|
|
50
58
|
/** A single attribute predicate, externally tagged as `nidus` encodes `Predicate`. */
|
|
@@ -355,6 +363,13 @@ interface OrderBy {
|
|
|
355
363
|
field: string;
|
|
356
364
|
descending?: boolean;
|
|
357
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* How several named-vector scores fold into one per-record score, before top-k
|
|
368
|
+
* selection (nidus-85t). `"Max"` (the default) takes the best weighted per-name score;
|
|
369
|
+
* an absent name then contributes nothing and carries no penalty. `"Sum"` adds every
|
|
370
|
+
* weighted named score. Meaningless when {@link SearchOptions.names} is empty.
|
|
371
|
+
*/
|
|
372
|
+
type Pool = "Max" | "Sum";
|
|
358
373
|
/** Ranking knobs shared by {@link NidusClient.search} and {@link NidusClient.textSearch}. */
|
|
359
374
|
interface RankingOptions {
|
|
360
375
|
rankBy?: RankBy;
|
|
@@ -429,6 +444,21 @@ interface SearchOptions extends ProjectionOptions, RankingOptions {
|
|
|
429
444
|
exact?: boolean;
|
|
430
445
|
/** See {@link RerankOptions}. `query` is required here. */
|
|
431
446
|
rerank?: RerankOptions;
|
|
447
|
+
/**
|
|
448
|
+
* Named vectors to score (nidus-85t), each declared on the collection first with
|
|
449
|
+
* {@link NidusClient.setVectorNames}. Omitted or empty (the default, and the only
|
|
450
|
+
* shape a pre-nidus-85t caller ever sends) searches only the reserved `"default"`
|
|
451
|
+
* vector, so an existing call is unaffected. A record is scored on whichever of
|
|
452
|
+
* these names it actually carries, reduced to one score by `pool`.
|
|
453
|
+
*/
|
|
454
|
+
names?: string[];
|
|
455
|
+
/**
|
|
456
|
+
* Per-name weight multiplying that name's score before pooling. A name absent here
|
|
457
|
+
* weights `1`. Meaningless when `names` is empty.
|
|
458
|
+
*/
|
|
459
|
+
nameWeights?: Record<string, number>;
|
|
460
|
+
/** How several named scores fold into one record score (default `"Max"`). See {@link Pool}. */
|
|
461
|
+
pool?: Pool;
|
|
432
462
|
}
|
|
433
463
|
/**
|
|
434
464
|
* Options for {@link NidusClient.searchSimilar}. `collection`/`id` name the source
|
|
@@ -587,6 +617,13 @@ interface HybridSearchBase extends AnnotationOptions {
|
|
|
587
617
|
expand?: Expand;
|
|
588
618
|
/** See {@link RerankOptions}. `query` is required here. */
|
|
589
619
|
rerank?: RerankOptions;
|
|
620
|
+
/**
|
|
621
|
+
* Cap the fused hits carrying any one value of an attribute (nidus-29ui). Applied on
|
|
622
|
+
* the shared cap → MMR → page-cut tail, same as {@link NidusClient.search}.
|
|
623
|
+
*/
|
|
624
|
+
limitPer?: LimitPer;
|
|
625
|
+
/** MMR lambda spreading the fused page in vector space (nidus-29ui). See {@link RankingOptions.diversity}. */
|
|
626
|
+
diversity?: number;
|
|
590
627
|
}
|
|
591
628
|
/** Options for {@link NidusClient.hybridSearch} (vector + BM25 fused via RRF). */
|
|
592
629
|
type HybridSearchOptions = HybridSearchBase & HybridQuerySpelling;
|
|
@@ -757,6 +794,47 @@ interface RecallOptions {
|
|
|
757
794
|
*/
|
|
758
795
|
rankBy?: RankBy;
|
|
759
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* One statement's answer from {@link NidusClient.query}: a ranked/listed statement decodes
|
|
799
|
+
* to a bare {@link Hit} array, or to `{hits, plan}` when it asked `WITH (plan)`; a `GROUP BY`
|
|
800
|
+
* statement decodes to an {@link Aggregation}.
|
|
801
|
+
*/
|
|
802
|
+
type QueryAnswer = Hit[] | {
|
|
803
|
+
hits: Hit[];
|
|
804
|
+
plan: QueryPlan;
|
|
805
|
+
} | Aggregation;
|
|
806
|
+
/**
|
|
807
|
+
* One compiled statement from {@link NidusClient.compile}: the typed value the SQL front end
|
|
808
|
+
* would hand the matching `Store` method (`search`/`text_search`/`hybrid_search`/`list`/
|
|
809
|
+
* `aggregate`), rendered for introspection only. `opts` (and, for `text_search`/`hybrid`,
|
|
810
|
+
* `query`/`text`) are the server's raw snake_case JSON — never executed, so never decoded
|
|
811
|
+
* into this SDK's own camelCase option shapes.
|
|
812
|
+
*/
|
|
813
|
+
type Compiled = {
|
|
814
|
+
kind: "search";
|
|
815
|
+
collections: string[];
|
|
816
|
+
vector: number[];
|
|
817
|
+
opts: Record<string, unknown>;
|
|
818
|
+
} | {
|
|
819
|
+
kind: "text_search";
|
|
820
|
+
collections: string[];
|
|
821
|
+
query: unknown;
|
|
822
|
+
opts: Record<string, unknown>;
|
|
823
|
+
} | {
|
|
824
|
+
kind: "hybrid";
|
|
825
|
+
collections: string[];
|
|
826
|
+
vector: number[];
|
|
827
|
+
text: unknown;
|
|
828
|
+
opts: Record<string, unknown>;
|
|
829
|
+
} | {
|
|
830
|
+
kind: "list";
|
|
831
|
+
collections: string[];
|
|
832
|
+
opts: Record<string, unknown>;
|
|
833
|
+
} | {
|
|
834
|
+
kind: "aggregate";
|
|
835
|
+
collections: string[];
|
|
836
|
+
opts: Record<string, unknown>;
|
|
837
|
+
};
|
|
760
838
|
|
|
761
839
|
/** Minimal `fetch` signature the client needs — satisfied by the platform global. */
|
|
762
840
|
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
@@ -839,6 +917,12 @@ declare class NidusClient {
|
|
|
839
917
|
* paid at write time and in memory. Pass an empty array to drop the declaration.
|
|
840
918
|
*/
|
|
841
919
|
setFilterIndex(name: string, fields: (string | FilterIndexField)[]): Promise<void>;
|
|
920
|
+
/**
|
|
921
|
+
* Declare the named-vector fields a collection accepts on upsert and search, beyond
|
|
922
|
+
* the reserved `"default"` vector (nidus-85t). Upserting an undeclared name is a
|
|
923
|
+
* `400` naming it; mirrors {@link NidusClient.setFtsSchema}'s declare-then-use shape.
|
|
924
|
+
*/
|
|
925
|
+
setVectorNames(name: string, names: string[]): Promise<void>;
|
|
842
926
|
/** Vector (cosine) nearest-neighbour search. Empty `scope` searches all collections. */
|
|
843
927
|
search(opts: SearchOptions): Promise<Hit[]>;
|
|
844
928
|
/** Like {@link NidusClient.search}, but also reports the scan strategy the server took. */
|
|
@@ -892,6 +976,22 @@ declare class NidusClient {
|
|
|
892
976
|
* in-RAM index alone — no record is built and no vector is read.
|
|
893
977
|
*/
|
|
894
978
|
aggregate(opts?: AggregateOptions): Promise<Aggregation>;
|
|
979
|
+
/**
|
|
980
|
+
* Compile and run a `SELECT ...` script against `POST /query` (SPEC §7.12). A single
|
|
981
|
+
* statement decodes to its own answer (hits, `{hits, plan}`, or an {@link Aggregation});
|
|
982
|
+
* a `;`-separated script answers one {@link QueryAnswer} per statement, in request order.
|
|
983
|
+
* A parse error rejects with the server's message verbatim (byte offset and §7 section).
|
|
984
|
+
*/
|
|
985
|
+
query(sql: string): Promise<QueryAnswer | QueryAnswer[]>;
|
|
986
|
+
/**
|
|
987
|
+
* Compile a `SELECT ...` script without running it: the typed value(s) the matching
|
|
988
|
+
* `Store` method would receive. Always an array, one entry per `;`-separated statement.
|
|
989
|
+
*/
|
|
990
|
+
compile(sql: string): Promise<Compiled[]>;
|
|
991
|
+
/** A wire hit's shape, distinguishing a bare hits-answer from a batch of answers. */
|
|
992
|
+
private isHitShaped;
|
|
993
|
+
/** Decode one statement's `/query` answer: hits (bare or `{hits, plan}`), or an aggregation. */
|
|
994
|
+
private decodeQueryAnswer;
|
|
895
995
|
/**
|
|
896
996
|
* Answer several vector queries in one round-trip (16 max). Returns one ranking per
|
|
897
997
|
* query in request order, or — with `opts.fuse` — a single array holding the one fused
|
|
@@ -1052,4 +1152,4 @@ declare function decodeValue(value: Value): DecodedValue;
|
|
|
1052
1152
|
/** Decode a whole wire `attrs` map back to plain JS values. */
|
|
1053
1153
|
declare function decodeAttrs(attrs: Record<string, Value>): Record<string, DecodedValue>;
|
|
1054
1154
|
|
|
1055
|
-
export { type AggregateOptions, type Aggregation, type AnnInfo, type AnnotationOptions, type Annotations, type AttrInput, type ClauseScore, type ClusterStatus, type CodeFileHit, type CodeSearchOptions, type CodeSymbolHit, type Decay, type DecodedRecord, type DecodedValue, type Expand, type Expansion, type FetchLike, type Filter, type FilterIndexField, type Footprint, type Fragment, type FtsCombine, type FtsField, type Highlight, type HighlightOptions, type Hit, type HybridQuerySpelling, type HybridSearchBase, type HybridSearchOptions, type LegScore, type LimitPer, type ListOptions, NidusClient, type NidusClientOptions, NidusError, type NidusRecord, type OrderBy, type PlanCandidates, type PlanNarrowing, type PlanTimings, type Predicate, type ProjectionOptions, type QueryPath, type QueryPlan, type RankBy, type RankingOptions, type Readiness, type RecallOptions, type RecordInput, type RememberOptions, type RememberResult, type RerankOptions, type Rollup, type SearchOptions, type SimilarSearchOptions, type Stats, type StoreVersions, type SuggestOptions, type Suggestion, type Suggestions, type TextClause, type TextQuerySpelling, type TextSearchBase, type TextSearchOptions, type Value, decodeAttrs, decodeValue, encodeAttrs, encodeValue, f, v };
|
|
1155
|
+
export { type AggregateOptions, type Aggregation, type AnnInfo, type AnnotationOptions, type Annotations, type AttrInput, type ClauseScore, type ClusterStatus, type CodeFileHit, type CodeSearchOptions, type CodeSymbolHit, type Compiled, type Decay, type DecodedRecord, type DecodedValue, type Expand, type Expansion, type FetchLike, type Filter, type FilterIndexField, type Footprint, type Fragment, type FtsCombine, type FtsField, type Highlight, type HighlightOptions, type Hit, type HybridQuerySpelling, type HybridSearchBase, type HybridSearchOptions, type LegScore, type LimitPer, type ListOptions, NidusClient, type NidusClientOptions, NidusError, type NidusRecord, type OrderBy, type PlanCandidates, type PlanNarrowing, type PlanTimings, type Predicate, type ProjectionOptions, type QueryAnswer, type QueryPath, type QueryPlan, type RankBy, type RankingOptions, type Readiness, type RecallOptions, type RecordInput, type RememberOptions, type RememberResult, type RerankOptions, type Rollup, type SearchOptions, type SimilarSearchOptions, type Stats, type StoreVersions, type SuggestOptions, type Suggestion, type Suggestions, type TextClause, type TextQuerySpelling, type TextSearchBase, type TextSearchOptions, type Value, decodeAttrs, decodeValue, encodeAttrs, encodeValue, f, v };
|
package/dist/index.js
CHANGED
|
@@ -256,6 +256,7 @@ var NidusClient = class {
|
|
|
256
256
|
const wire = records.map((r) => ({
|
|
257
257
|
id: r.id,
|
|
258
258
|
...r.vector !== void 0 ? { vector: r.vector } : {},
|
|
259
|
+
...r.vectors !== void 0 ? { vectors: r.vectors } : {},
|
|
259
260
|
attrs: encodeAttrs(r.attrs)
|
|
260
261
|
}));
|
|
261
262
|
const res = await this.request(
|
|
@@ -292,6 +293,7 @@ var NidusClient = class {
|
|
|
292
293
|
return recs.map((r) => ({
|
|
293
294
|
id: r.id,
|
|
294
295
|
...r.vector !== void 0 ? { vector: r.vector } : {},
|
|
296
|
+
...r.vectors !== void 0 ? { vectors: r.vectors } : {},
|
|
295
297
|
attrs: decodeAttrs(r.attrs)
|
|
296
298
|
}));
|
|
297
299
|
}
|
|
@@ -319,6 +321,14 @@ var NidusClient = class {
|
|
|
319
321
|
fields: fields.map(encodeFilterIndexField)
|
|
320
322
|
});
|
|
321
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Declare the named-vector fields a collection accepts on upsert and search, beyond
|
|
326
|
+
* the reserved `"default"` vector (nidus-85t). Upserting an undeclared name is a
|
|
327
|
+
* `400` naming it; mirrors {@link NidusClient.setFtsSchema}'s declare-then-use shape.
|
|
328
|
+
*/
|
|
329
|
+
async setVectorNames(name, names) {
|
|
330
|
+
await this.request("POST", `/collections/${enc(name)}/vector-names`, { names });
|
|
331
|
+
}
|
|
322
332
|
// ── Search ──────────────────────────────────────────────────────────────
|
|
323
333
|
/** Vector (cosine) nearest-neighbour search. Empty `scope` searches all collections. */
|
|
324
334
|
search(opts) {
|
|
@@ -336,7 +346,10 @@ var NidusClient = class {
|
|
|
336
346
|
limit_per: opts.limitPer,
|
|
337
347
|
diversity: opts.diversity,
|
|
338
348
|
expand: encodeExpand(opts.expand),
|
|
339
|
-
rerank: encodeRerank(opts.rerank)
|
|
349
|
+
rerank: encodeRerank(opts.rerank),
|
|
350
|
+
names: opts.names,
|
|
351
|
+
name_weights: opts.nameWeights,
|
|
352
|
+
pool: opts.pool
|
|
340
353
|
});
|
|
341
354
|
}
|
|
342
355
|
/** Like {@link NidusClient.search}, but also reports the scan strategy the server took. */
|
|
@@ -355,7 +368,10 @@ var NidusClient = class {
|
|
|
355
368
|
limit_per: opts.limitPer,
|
|
356
369
|
diversity: opts.diversity,
|
|
357
370
|
expand: encodeExpand(opts.expand),
|
|
358
|
-
rerank: encodeRerank(opts.rerank)
|
|
371
|
+
rerank: encodeRerank(opts.rerank),
|
|
372
|
+
names: opts.names,
|
|
373
|
+
name_weights: opts.nameWeights,
|
|
374
|
+
pool: opts.pool
|
|
359
375
|
});
|
|
360
376
|
}
|
|
361
377
|
/** Records most like an existing one. The source record itself is never returned. */
|
|
@@ -491,7 +507,9 @@ var NidusClient = class {
|
|
|
491
507
|
vector_weight: opts.vectorWeight,
|
|
492
508
|
text_weight: opts.textWeight,
|
|
493
509
|
expand: encodeExpand(opts.expand),
|
|
494
|
-
rerank: encodeRerank(opts.rerank)
|
|
510
|
+
rerank: encodeRerank(opts.rerank),
|
|
511
|
+
limit_per: opts.limitPer,
|
|
512
|
+
diversity: opts.diversity
|
|
495
513
|
});
|
|
496
514
|
}
|
|
497
515
|
/** Like {@link NidusClient.hybridSearch}, but also reports the scan strategy taken. */
|
|
@@ -510,7 +528,9 @@ var NidusClient = class {
|
|
|
510
528
|
vector_weight: opts.vectorWeight,
|
|
511
529
|
text_weight: opts.textWeight,
|
|
512
530
|
expand: encodeExpand(opts.expand),
|
|
513
|
-
rerank: encodeRerank(opts.rerank)
|
|
531
|
+
rerank: encodeRerank(opts.rerank),
|
|
532
|
+
limit_per: opts.limitPer,
|
|
533
|
+
diversity: opts.diversity
|
|
514
534
|
});
|
|
515
535
|
}
|
|
516
536
|
/** Metadata-only listing (no vector), paginated by `offset`/`limit`. */
|
|
@@ -554,6 +574,60 @@ var NidusClient = class {
|
|
|
554
574
|
...res.groups_truncated ? { groupsTruncated: true } : {}
|
|
555
575
|
};
|
|
556
576
|
}
|
|
577
|
+
// ── SQL (SPEC §7.12) ────────────────────────────────────────────────────
|
|
578
|
+
/**
|
|
579
|
+
* Compile and run a `SELECT ...` script against `POST /query` (SPEC §7.12). A single
|
|
580
|
+
* statement decodes to its own answer (hits, `{hits, plan}`, or an {@link Aggregation});
|
|
581
|
+
* a `;`-separated script answers one {@link QueryAnswer} per statement, in request order.
|
|
582
|
+
* A parse error rejects with the server's message verbatim (byte offset and §7 section).
|
|
583
|
+
*/
|
|
584
|
+
async query(sql) {
|
|
585
|
+
const raw = await this.request("POST", "/query", { sql });
|
|
586
|
+
if (Array.isArray(raw) && raw.length > 0 && !this.isHitShaped(raw[0])) {
|
|
587
|
+
return raw.map((a) => this.decodeQueryAnswer(a));
|
|
588
|
+
}
|
|
589
|
+
return this.decodeQueryAnswer(raw);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Compile a `SELECT ...` script without running it: the typed value(s) the matching
|
|
593
|
+
* `Store` method would receive. Always an array, one entry per `;`-separated statement.
|
|
594
|
+
*/
|
|
595
|
+
async compile(sql) {
|
|
596
|
+
const raw = await this.request("POST", "/query", {
|
|
597
|
+
sql,
|
|
598
|
+
compile_only: true
|
|
599
|
+
});
|
|
600
|
+
return Array.isArray(raw) ? raw : [raw];
|
|
601
|
+
}
|
|
602
|
+
/** A wire hit's shape, distinguishing a bare hits-answer from a batch of answers. */
|
|
603
|
+
isHitShaped(x) {
|
|
604
|
+
return typeof x === "object" && x !== null && !Array.isArray(x) && typeof x.id === "string";
|
|
605
|
+
}
|
|
606
|
+
/** Decode one statement's `/query` answer: hits (bare or `{hits, plan}`), or an aggregation. */
|
|
607
|
+
decodeQueryAnswer(raw) {
|
|
608
|
+
if (Array.isArray(raw)) {
|
|
609
|
+
return raw.map((h) => this.decodeHit(h));
|
|
610
|
+
}
|
|
611
|
+
const obj = raw;
|
|
612
|
+
if ("count" in obj) {
|
|
613
|
+
return {
|
|
614
|
+
count: obj.count,
|
|
615
|
+
sums: decodeAttrs(obj.sums),
|
|
616
|
+
...obj.groups ? {
|
|
617
|
+
groups: obj.groups.map((g) => ({
|
|
618
|
+
value: g.value === null ? null : decodeValue(g.value),
|
|
619
|
+
count: g.count,
|
|
620
|
+
sums: decodeAttrs(g.sums)
|
|
621
|
+
}))
|
|
622
|
+
} : {},
|
|
623
|
+
...obj.groups_truncated ? { groupsTruncated: true } : {}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
hits: obj.hits.map((h) => this.decodeHit(h)),
|
|
628
|
+
plan: decodeQueryPlan(obj.plan)
|
|
629
|
+
};
|
|
630
|
+
}
|
|
557
631
|
/**
|
|
558
632
|
* Answer several vector queries in one round-trip (16 max). Returns one ranking per
|
|
559
633
|
* query in request order, or — with `opts.fuse` — a single array holding the one fused
|