@h-ai/vecdb 0.1.0-alpha5
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/LICENSE +202 -0
- package/README.md +95 -0
- package/dist/index.d.ts +477 -0
- package/dist/index.js +1056 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as _h_ai_core from '@h-ai/core';
|
|
3
|
+
import { HaiResult } from '@h-ai/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @h-ai/vecdb — 向量数据库配置 Schema
|
|
7
|
+
*
|
|
8
|
+
* 本文件定义向量数据库模块的错误码常量、Zod Schema 和配置类型。
|
|
9
|
+
* 支持 LanceDB(默认)、pgvector、Qdrant 三种后端。
|
|
10
|
+
* @module vecdb-config
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 向量数据库类型枚举
|
|
15
|
+
*
|
|
16
|
+
* 支持的向量数据库类型:
|
|
17
|
+
* - `lancedb` — LanceDB 嵌入式向量数据库(默认)
|
|
18
|
+
* - `pgvector` — PostgreSQL + pgvector 扩展
|
|
19
|
+
* - `qdrant` — Qdrant 向量搜索引擎
|
|
20
|
+
*/
|
|
21
|
+
declare const VecdbTypeSchema: z.ZodEnum<{
|
|
22
|
+
lancedb: "lancedb";
|
|
23
|
+
pgvector: "pgvector";
|
|
24
|
+
qdrant: "qdrant";
|
|
25
|
+
}>;
|
|
26
|
+
/** 向量数据库类型 */
|
|
27
|
+
type VecdbType = z.infer<typeof VecdbTypeSchema>;
|
|
28
|
+
/**
|
|
29
|
+
* 距离度量类型
|
|
30
|
+
*
|
|
31
|
+
* - `cosine` — 余弦相似度(默认,适用于文本嵌入)
|
|
32
|
+
* - `euclidean` — 欧氏距离(L2)
|
|
33
|
+
* - `dot` — 内积(点积)
|
|
34
|
+
*/
|
|
35
|
+
declare const DistanceMetricSchema: z.ZodDefault<z.ZodEnum<{
|
|
36
|
+
cosine: "cosine";
|
|
37
|
+
euclidean: "euclidean";
|
|
38
|
+
dot: "dot";
|
|
39
|
+
}>>;
|
|
40
|
+
/** 距离度量类型 */
|
|
41
|
+
type DistanceMetric = z.infer<typeof DistanceMetricSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* LanceDB 配置 Schema
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* { type: 'lancedb', path: './data/vecdb' }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare const LancedbConfigSchema: z.ZodObject<{
|
|
51
|
+
type: z.ZodLiteral<"lancedb">;
|
|
52
|
+
path: z.ZodString;
|
|
53
|
+
metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
54
|
+
cosine: "cosine";
|
|
55
|
+
euclidean: "euclidean";
|
|
56
|
+
dot: "dot";
|
|
57
|
+
}>>>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
/** LanceDB 配置类型 */
|
|
60
|
+
type LancedbConfig = z.infer<typeof LancedbConfigSchema>;
|
|
61
|
+
/**
|
|
62
|
+
* pgvector 索引类型
|
|
63
|
+
*
|
|
64
|
+
* - `ivfflat` — IVFFlat 索引(适合中等规模数据)
|
|
65
|
+
* - `hnsw` — HNSW 索引(适合大规模数据,检索速度更快)
|
|
66
|
+
*/
|
|
67
|
+
declare const PgvectorIndexTypeSchema: z.ZodDefault<z.ZodEnum<{
|
|
68
|
+
ivfflat: "ivfflat";
|
|
69
|
+
hnsw: "hnsw";
|
|
70
|
+
}>>;
|
|
71
|
+
/**
|
|
72
|
+
* pgvector 配置 Schema
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* // 使用连接字符串
|
|
77
|
+
* { type: 'pgvector', url: 'postgres://user:pass@localhost:5432/mydb' }
|
|
78
|
+
*
|
|
79
|
+
* // 使用分开的字段
|
|
80
|
+
* {
|
|
81
|
+
* type: 'pgvector',
|
|
82
|
+
* host: 'localhost',
|
|
83
|
+
* port: 5432,
|
|
84
|
+
* database: 'mydb',
|
|
85
|
+
* user: 'admin',
|
|
86
|
+
* password: 'secret'
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare const PgvectorConfigSchema: z.ZodObject<{
|
|
91
|
+
type: z.ZodLiteral<"pgvector">;
|
|
92
|
+
url: z.ZodOptional<z.ZodString>;
|
|
93
|
+
host: z.ZodDefault<z.ZodString>;
|
|
94
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
95
|
+
database: z.ZodString;
|
|
96
|
+
user: z.ZodOptional<z.ZodString>;
|
|
97
|
+
password: z.ZodOptional<z.ZodString>;
|
|
98
|
+
indexType: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
99
|
+
ivfflat: "ivfflat";
|
|
100
|
+
hnsw: "hnsw";
|
|
101
|
+
}>>>;
|
|
102
|
+
metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
103
|
+
cosine: "cosine";
|
|
104
|
+
euclidean: "euclidean";
|
|
105
|
+
dot: "dot";
|
|
106
|
+
}>>>;
|
|
107
|
+
tablePrefix: z.ZodDefault<z.ZodString>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
/** pgvector 配置类型 */
|
|
110
|
+
type PgvectorConfig = z.infer<typeof PgvectorConfigSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* Qdrant 配置 Schema
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* { type: 'qdrant', url: 'http://localhost:6333' }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare const QdrantConfigSchema: z.ZodObject<{
|
|
120
|
+
type: z.ZodLiteral<"qdrant">;
|
|
121
|
+
url: z.ZodDefault<z.ZodString>;
|
|
122
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
123
|
+
metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
124
|
+
cosine: "cosine";
|
|
125
|
+
euclidean: "euclidean";
|
|
126
|
+
dot: "dot";
|
|
127
|
+
}>>>;
|
|
128
|
+
}, z.core.$strip>;
|
|
129
|
+
/** Qdrant 配置类型 */
|
|
130
|
+
type QdrantConfig = z.infer<typeof QdrantConfigSchema>;
|
|
131
|
+
/**
|
|
132
|
+
* 统一向量数据库配置 Schema(判别联合体)
|
|
133
|
+
*
|
|
134
|
+
* 根据 `type` 字段区分不同向量数据库类型的配置。
|
|
135
|
+
*/
|
|
136
|
+
declare const VecdbConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
137
|
+
type: z.ZodLiteral<"lancedb">;
|
|
138
|
+
path: z.ZodString;
|
|
139
|
+
metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
140
|
+
cosine: "cosine";
|
|
141
|
+
euclidean: "euclidean";
|
|
142
|
+
dot: "dot";
|
|
143
|
+
}>>>;
|
|
144
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
145
|
+
type: z.ZodLiteral<"pgvector">;
|
|
146
|
+
url: z.ZodOptional<z.ZodString>;
|
|
147
|
+
host: z.ZodDefault<z.ZodString>;
|
|
148
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
149
|
+
database: z.ZodString;
|
|
150
|
+
user: z.ZodOptional<z.ZodString>;
|
|
151
|
+
password: z.ZodOptional<z.ZodString>;
|
|
152
|
+
indexType: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
153
|
+
ivfflat: "ivfflat";
|
|
154
|
+
hnsw: "hnsw";
|
|
155
|
+
}>>>;
|
|
156
|
+
metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
157
|
+
cosine: "cosine";
|
|
158
|
+
euclidean: "euclidean";
|
|
159
|
+
dot: "dot";
|
|
160
|
+
}>>>;
|
|
161
|
+
tablePrefix: z.ZodDefault<z.ZodString>;
|
|
162
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
163
|
+
type: z.ZodLiteral<"qdrant">;
|
|
164
|
+
url: z.ZodDefault<z.ZodString>;
|
|
165
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
166
|
+
metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
167
|
+
cosine: "cosine";
|
|
168
|
+
euclidean: "euclidean";
|
|
169
|
+
dot: "dot";
|
|
170
|
+
}>>>;
|
|
171
|
+
}, z.core.$strip>], "type">;
|
|
172
|
+
/** 向量数据库配置类型(判别联合体) */
|
|
173
|
+
type VecdbConfig = z.infer<typeof VecdbConfigSchema>;
|
|
174
|
+
/**
|
|
175
|
+
* 向量数据库配置输入类型(用于 init 等入口)
|
|
176
|
+
*
|
|
177
|
+
* 说明:Zod 的 default 会让输入端字段可省略,但输出端字段为必填。
|
|
178
|
+
* 因此对外 API(如 vecdb.init)更适合接收 VecdbConfigInput。
|
|
179
|
+
*/
|
|
180
|
+
type VecdbConfigInput = z.input<typeof VecdbConfigSchema>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Vecdb 模块标准错误定义对象。
|
|
184
|
+
*/
|
|
185
|
+
declare const HaiVecdbError: {
|
|
186
|
+
readonly CONNECTION_FAILED: _h_ai_core.HaiErrorDef;
|
|
187
|
+
readonly QUERY_FAILED: _h_ai_core.HaiErrorDef;
|
|
188
|
+
readonly COLLECTION_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
189
|
+
readonly COLLECTION_ALREADY_EXISTS: _h_ai_core.HaiErrorDef;
|
|
190
|
+
readonly DIMENSION_MISMATCH: _h_ai_core.HaiErrorDef;
|
|
191
|
+
readonly INSERT_FAILED: _h_ai_core.HaiErrorDef;
|
|
192
|
+
readonly DELETE_FAILED: _h_ai_core.HaiErrorDef;
|
|
193
|
+
readonly UPDATE_FAILED: _h_ai_core.HaiErrorDef;
|
|
194
|
+
readonly INDEX_BUILD_FAILED: _h_ai_core.HaiErrorDef;
|
|
195
|
+
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
196
|
+
readonly CONFIG_ERROR: _h_ai_core.HaiErrorDef;
|
|
197
|
+
readonly UNSUPPORTED_TYPE: _h_ai_core.HaiErrorDef;
|
|
198
|
+
readonly DRIVER_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
199
|
+
readonly SERIALIZATION_FAILED: _h_ai_core.HaiErrorDef;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* 向量文档接口
|
|
203
|
+
*
|
|
204
|
+
* 表示一条存入向量数据库的记录,包含向量、文本内容和元数据。
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* const doc: VectorDocument = {
|
|
209
|
+
* id: 'doc-001',
|
|
210
|
+
* vector: [0.1, 0.2, 0.3, ...],
|
|
211
|
+
* content: '这是文档内容',
|
|
212
|
+
* metadata: { source: 'wiki', page: 1 },
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
interface VectorDocument {
|
|
217
|
+
/** 文档唯一标识 */
|
|
218
|
+
id: string;
|
|
219
|
+
/** 向量数据(浮点数组) */
|
|
220
|
+
vector: number[];
|
|
221
|
+
/** 文本内容(可选,用于存储原始文本) */
|
|
222
|
+
content?: string;
|
|
223
|
+
/** 元数据(可选,用于存储附加信息) */
|
|
224
|
+
metadata?: Record<string, unknown>;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 向量搜索选项
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const options: VectorSearchOptions = {
|
|
232
|
+
* topK: 10,
|
|
233
|
+
* filter: { source: 'wiki' },
|
|
234
|
+
* minScore: 0.7,
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
interface VectorSearchOptions {
|
|
239
|
+
/** 返回的最大结果数(默认 10) */
|
|
240
|
+
topK?: number;
|
|
241
|
+
/** 元数据过滤条件(键值对,精确匹配) */
|
|
242
|
+
filter?: Record<string, unknown>;
|
|
243
|
+
/** 最低相似度阈值(0-1,低于此值的结果将被过滤) */
|
|
244
|
+
minScore?: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* 向量搜索结果
|
|
248
|
+
*
|
|
249
|
+
* 包含匹配的文档和相似度得分。
|
|
250
|
+
*/
|
|
251
|
+
interface VectorSearchResult {
|
|
252
|
+
/** 文档唯一标识 */
|
|
253
|
+
id: string;
|
|
254
|
+
/** 相似度得分(0-1,越高越相似) */
|
|
255
|
+
score: number;
|
|
256
|
+
/** 文本内容(如果存储时包含) */
|
|
257
|
+
content?: string;
|
|
258
|
+
/** 元数据(如果存储时包含) */
|
|
259
|
+
metadata?: Record<string, unknown>;
|
|
260
|
+
/** 原始向量(可选,默认不返回以节省传输) */
|
|
261
|
+
vector?: number[];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 集合信息接口
|
|
265
|
+
*
|
|
266
|
+
* 描述一个向量集合的元信息。
|
|
267
|
+
*/
|
|
268
|
+
interface CollectionInfo {
|
|
269
|
+
/** 集合名称 */
|
|
270
|
+
name: string;
|
|
271
|
+
/** 向量维度 */
|
|
272
|
+
dimension: number;
|
|
273
|
+
/** 距离度量类型 */
|
|
274
|
+
metric: DistanceMetric;
|
|
275
|
+
/** 集合中的文档数量 */
|
|
276
|
+
count: number;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 集合管理操作接口
|
|
280
|
+
*
|
|
281
|
+
* 通过 `vecdb.collection` 访问,管理向量集合的创建、删除和查询。
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* // 创建集合
|
|
286
|
+
* await vecdb.collection.create('my-docs', { dimension: 1536 })
|
|
287
|
+
*
|
|
288
|
+
* // 列出集合
|
|
289
|
+
* const result = await vecdb.collection.list()
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
interface CollectionOperations {
|
|
293
|
+
/**
|
|
294
|
+
* 创建集合
|
|
295
|
+
*
|
|
296
|
+
* @param name - 集合名称
|
|
297
|
+
* @param options - 创建选项
|
|
298
|
+
* @returns 成功返回 ok(undefined);集合已存在返回 COLLECTION_ALREADY_EXISTS
|
|
299
|
+
*/
|
|
300
|
+
create: (name: string, options: CollectionCreateOptions) => Promise<HaiResult<void>>;
|
|
301
|
+
/**
|
|
302
|
+
* 删除集合
|
|
303
|
+
*
|
|
304
|
+
* @param name - 集合名称
|
|
305
|
+
* @returns 成功返回 ok(undefined);集合不存在返回 COLLECTION_NOT_FOUND
|
|
306
|
+
*/
|
|
307
|
+
drop: (name: string) => Promise<HaiResult<void>>;
|
|
308
|
+
/**
|
|
309
|
+
* 判断集合是否存在
|
|
310
|
+
*
|
|
311
|
+
* @param name - 集合名称
|
|
312
|
+
* @returns 存在返回 true,不存在返回 false
|
|
313
|
+
*/
|
|
314
|
+
exists: (name: string) => Promise<HaiResult<boolean>>;
|
|
315
|
+
/**
|
|
316
|
+
* 获取集合信息
|
|
317
|
+
*
|
|
318
|
+
* @param name - 集合名称
|
|
319
|
+
* @returns 集合信息
|
|
320
|
+
*/
|
|
321
|
+
info: (name: string) => Promise<HaiResult<CollectionInfo>>;
|
|
322
|
+
/**
|
|
323
|
+
* 列出所有集合
|
|
324
|
+
*
|
|
325
|
+
* @returns 集合名称列表
|
|
326
|
+
*/
|
|
327
|
+
list: () => Promise<HaiResult<string[]>>;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 集合创建选项
|
|
331
|
+
*/
|
|
332
|
+
interface CollectionCreateOptions {
|
|
333
|
+
/** 向量维度(必填) */
|
|
334
|
+
dimension: number;
|
|
335
|
+
/** 距离度量(可选,默认使用全局配置中的 metric) */
|
|
336
|
+
metric?: DistanceMetric;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 向量操作接口
|
|
340
|
+
*
|
|
341
|
+
* 通过 `vecdb.vector` 访问,管理向量文档的增删改查和搜索。
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* // 插入向量
|
|
346
|
+
* await vecdb.vector.insert('my-docs', [
|
|
347
|
+
* { id: 'doc-1', vector: [...], content: '文档1' },
|
|
348
|
+
* { id: 'doc-2', vector: [...], content: '文档2' },
|
|
349
|
+
* ])
|
|
350
|
+
*
|
|
351
|
+
* // 搜索向量
|
|
352
|
+
* const result = await vecdb.vector.search('my-docs', queryVector, { topK: 5 })
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
interface VectorOperations {
|
|
356
|
+
/**
|
|
357
|
+
* 插入向量文档
|
|
358
|
+
*
|
|
359
|
+
* @param collection - 集合名称
|
|
360
|
+
* @param documents - 文档列表
|
|
361
|
+
* @returns 成功返回 ok(undefined)
|
|
362
|
+
*/
|
|
363
|
+
insert: (collection: string, documents: VectorDocument[]) => Promise<HaiResult<void>>;
|
|
364
|
+
/**
|
|
365
|
+
* 更新向量文档(按 id 匹配,整体替换)
|
|
366
|
+
*
|
|
367
|
+
* @param collection - 集合名称
|
|
368
|
+
* @param documents - 待更新的文档(id 必须已存在)
|
|
369
|
+
* @returns 成功返回 ok(undefined)
|
|
370
|
+
*/
|
|
371
|
+
upsert: (collection: string, documents: VectorDocument[]) => Promise<HaiResult<void>>;
|
|
372
|
+
/**
|
|
373
|
+
* 删除向量文档
|
|
374
|
+
*
|
|
375
|
+
* @param collection - 集合名称
|
|
376
|
+
* @param ids - 文档 ID 列表
|
|
377
|
+
* @returns 成功返回 ok(undefined)
|
|
378
|
+
*/
|
|
379
|
+
delete: (collection: string, ids: string[]) => Promise<HaiResult<void>>;
|
|
380
|
+
/**
|
|
381
|
+
* 向量搜索
|
|
382
|
+
*
|
|
383
|
+
* @param collection - 集合名称
|
|
384
|
+
* @param vector - 查询向量
|
|
385
|
+
* @param options - 搜索选项
|
|
386
|
+
* @returns 搜索结果列表(按相似度降序排列)
|
|
387
|
+
*/
|
|
388
|
+
search: (collection: string, vector: number[], options?: VectorSearchOptions) => Promise<HaiResult<VectorSearchResult[]>>;
|
|
389
|
+
/**
|
|
390
|
+
* 获取集合中的文档数量
|
|
391
|
+
*
|
|
392
|
+
* @param collection - 集合名称
|
|
393
|
+
* @returns 文档数量
|
|
394
|
+
*/
|
|
395
|
+
count: (collection: string) => Promise<HaiResult<number>>;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 向量数据库服务接口(通过 `vecdb` 对象访问)
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* import { vecdb } from '@h-ai/vecdb'
|
|
403
|
+
*
|
|
404
|
+
* // 初始化(LanceDB)
|
|
405
|
+
* await vecdb.init({ type: 'lancedb', path: './data/vecdb' })
|
|
406
|
+
*
|
|
407
|
+
* // 创建集合
|
|
408
|
+
* await vecdb.collection.create('docs', { dimension: 1536 })
|
|
409
|
+
*
|
|
410
|
+
* // 插入向量
|
|
411
|
+
* await vecdb.vector.insert('docs', [{ id: '1', vector: [...], content: '...' }])
|
|
412
|
+
*
|
|
413
|
+
* // 搜索
|
|
414
|
+
* const result = await vecdb.vector.search('docs', queryVector, { topK: 5 })
|
|
415
|
+
*
|
|
416
|
+
* // 关闭
|
|
417
|
+
* await vecdb.close()
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
interface VecdbFunctions {
|
|
421
|
+
/** 初始化向量数据库连接 */
|
|
422
|
+
init: (config: VecdbConfigInput) => Promise<HaiResult<void>>;
|
|
423
|
+
/** 关闭连接 */
|
|
424
|
+
close: () => Promise<HaiResult<void>>;
|
|
425
|
+
/** 当前配置(未初始化时为 null) */
|
|
426
|
+
readonly config: VecdbConfig | null;
|
|
427
|
+
/** 是否已初始化 */
|
|
428
|
+
readonly isInitialized: boolean;
|
|
429
|
+
/** 集合管理操作 */
|
|
430
|
+
readonly collection: CollectionOperations;
|
|
431
|
+
/** 向量操作 */
|
|
432
|
+
readonly vector: VectorOperations;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* @h-ai/vecdb — 向量数据库服务主入口
|
|
437
|
+
*
|
|
438
|
+
* 本文件提供统一的 `vecdb` 对象,聚合所有向量数据库操作功能。
|
|
439
|
+
* @module vecdb-main
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* 向量数据库服务对象
|
|
444
|
+
*
|
|
445
|
+
* 统一的向量数据库访问入口,提供以下功能:
|
|
446
|
+
* - `vecdb.init()` - 初始化连接
|
|
447
|
+
* - `vecdb.close()` - 关闭连接
|
|
448
|
+
* - `vecdb.collection` - 集合管理(创建/删除/查询)
|
|
449
|
+
* - `vecdb.vector` - 向量操作(插入/搜索/删除)
|
|
450
|
+
* - `vecdb.config` - 当前配置
|
|
451
|
+
* - `vecdb.isInitialized` - 初始化状态
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* import { vecdb } from '@h-ai/vecdb'
|
|
456
|
+
*
|
|
457
|
+
* // 初始化(LanceDB)
|
|
458
|
+
* await vecdb.init({ type: 'lancedb', path: './data/vecdb' })
|
|
459
|
+
*
|
|
460
|
+
* // 集合操作
|
|
461
|
+
* await vecdb.collection.create('docs', { dimension: 1536 })
|
|
462
|
+
*
|
|
463
|
+
* // 向量操作
|
|
464
|
+
* await vecdb.vector.insert('docs', [
|
|
465
|
+
* { id: '1', vector: [...], content: '文档内容' },
|
|
466
|
+
* ])
|
|
467
|
+
*
|
|
468
|
+
* // 搜索
|
|
469
|
+
* const result = await vecdb.vector.search('docs', queryVector, { topK: 5 })
|
|
470
|
+
*
|
|
471
|
+
* // 关闭
|
|
472
|
+
* await vecdb.close()
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
declare const vecdb: VecdbFunctions;
|
|
476
|
+
|
|
477
|
+
export { type CollectionCreateOptions, type CollectionInfo, type CollectionOperations, type DistanceMetric, DistanceMetricSchema, HaiVecdbError, type LancedbConfig, LancedbConfigSchema, type PgvectorConfig, PgvectorConfigSchema, PgvectorIndexTypeSchema, type QdrantConfig, QdrantConfigSchema, type VecdbConfig, type VecdbConfigInput, VecdbConfigSchema, type VecdbFunctions, type VecdbType, VecdbTypeSchema, type VectorDocument, type VectorOperations, type VectorSearchOptions, type VectorSearchResult, vecdb };
|