Repository navigation
Expand file tree
/
Copy pathvec_client.d.ts
More file actions
185 lines (148 loc) · 5.7 KB
/
Copy pathvec_client.d.ts
File metadata and controls
185 lines (148 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* VEC 2.0 Node.js Client SDK — TypeScript declarations.
*
* Local transport only in this version:
* - Windows: named pipe \\.\pipe\vec_<name>
* - Linux: unix socket /tmp/vec_<name>.sock
*
* Pair with vec_client.js. See PROTOCOL-2.0.md for the wire spec.
* See examples/node/ for the three storage-boundary examples.
*/
/// <reference types="node" />
export type VecLabel = string | Buffer;
export type VecData = Buffer | Uint8Array;
export type VecVector = ArrayLike<number>;
/** Bitmask controlling what each result record carries. */
export type Shape = number;
export interface VecRecord {
index: number;
/** Present only on query/qid; null for get/exists. */
distance: number | null;
/** Present when shape & SHAPE_LABEL; null otherwise or if label was empty. */
label: string | null;
/** Present when shape & SHAPE_DATA and non-empty; null otherwise. */
data: Buffer | null;
/** Present when shape & SHAPE_VECTOR. */
vector: Float32Array | null;
}
export interface VecExistsResult {
index: number;
/** Populated only when shape & SHAPE_LABEL. */
label?: string;
/** Populated only when shape & SHAPE_DATA. */
data?: Buffer;
}
export interface VecInfo {
dim: number;
count: number;
deleted: number;
fmt: 'f16' | 'f32';
/** Unix epoch seconds: GPU last in-process write; CPU tensor-file mtime. */
mtime: number;
crc: number;
/** 0 = mismatch/new, 1 = ok, 255 = legacy tensor file without CRC trailer. */
crcOk: number;
name: string;
/** Always 2 in this version. */
protocol: number;
}
export interface VecSaveResult {
savedCount: number;
crc: number;
}
export interface VecClusterEntry {
/** Slot indices belonging to this cluster. */
members: number[];
/**
* Arithmetic mean of the member vectors (fp32, length = dim of the DB).
* Use it to spot degenerate-attractor clusters: a centroid with suspiciously
* small magnitude, or members with high pairwise distance, often holds
* low-confidence/fallback embeddings rather than a real coherent group.
*/
centroid: Float32Array;
}
export interface VecClusterResult {
clusters: VecClusterEntry[];
/** Indices of slots that didn't fall into any cluster. */
noise: number[];
}
export interface PushOpts {
label?: VecLabel | null;
data?: VecData | null;
}
export interface QueryOpts {
cosine?: boolean;
shape?: Shape;
}
export interface ExistsOpts {
/** SHAPE_VECTOR is ignored; pass SHAPE_LABEL / SHAPE_DATA bits to fetch them. */
shape?: Shape;
}
export interface GetOpts {
shape?: Shape;
}
export interface ClusterOpts {
cosine?: boolean;
minPts?: number;
}
export interface DistinctOpts {
cosine?: boolean;
}
export type IndexOrLabel = number | VecLabel;
declare class VecClient {
/**
* Connect to the local instance named `name`.
* Windows -> \\.\pipe\vec_<name>, Linux -> /tmp/vec_<name>.sock.
*/
constructor(name: string);
/** Open the underlying pipe / socket. Must be awaited before issuing commands. */
connect(): Promise<void>;
/** Insert a record. Non-empty inline data requires a label. Returns slot index. */
push(vector: VecVector, opts?: PushOpts): Promise<number>;
/** Nearest-neighbor search by query vector. */
query(vector: VecVector, opts?: QueryOpts): Promise<VecRecord[]>;
/** Byte-exact lookup. Returns null if no match. */
exists(vector: VecVector, opts?: ExistsOpts): Promise<VecExistsResult | null>;
/** Nearest-neighbor search using a stored vector (by index or label). */
qid(indexOrLabel: IndexOrLabel, opts?: QueryOpts): Promise<VecRecord[]>;
/**
* Fetch records:
* number -> single by index
* number[] -> batch
* string/Buffer -> single by label (may return multiple)
*/
get(target: number | number[] | VecLabel, opts?: GetOpts): Promise<VecRecord[]>;
/** Overwrite vector in place. Does not touch label or data. */
update(indexOrLabel: IndexOrLabel, vector: VecVector): Promise<void>;
/** Set or clear label for a slot. Empty/null clears. */
setLabel(index: number, label: VecLabel | null): Promise<void>;
/** Tombstone a slot. Also clears its label and data. */
delete(indexOrLabel: IndexOrLabel): Promise<void>;
/** Remove the last pushed record. Also clears its label and data. */
undo(): Promise<void>;
/** Request persistence; --memory acknowledges without writing. */
save(): Promise<VecSaveResult>;
/** DB metadata snapshot. */
info(): Promise<VecInfo>;
/** Set or clear sidecar payload. Empty clears. */
setData(indexOrLabel: IndexOrLabel, data: VecData | null): Promise<void>;
/** Fetch sidecar payload. Returns an empty Buffer when the slot has none. */
getData(indexOrLabel: IndexOrLabel): Promise<Buffer>;
/** DBSCAN clustering. Returns members + centroid per cluster; centroid is the
* arithmetic mean of member vectors (fp32 even for f16 DBs). */
cluster(eps: number, opts?: ClusterOpts): Promise<VecClusterResult>;
/** Farthest-point sampling. */
distinct(k: number, opts?: DistinctOpts): Promise<Array<number | string>>;
/** One representative per DBSCAN cluster. */
represent(eps: number, opts?: ClusterOpts): Promise<Array<number | string>>;
/** Close the underlying pipe / socket. */
close(): void;
// ---- static shape mask constants ----
static readonly SHAPE_VECTOR: Shape;
static readonly SHAPE_LABEL: Shape;
static readonly SHAPE_DATA: Shape;
/** SHAPE_VECTOR | SHAPE_LABEL | SHAPE_DATA — the default for query/qid/get. */
static readonly SHAPE_FULL: Shape;
static readonly PROTOCOL_VERSION: 2;
}
export = VecClient;