@h-ai/vecdb 0.1.0-alpha.33 → 0.1.0-alpha.35

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 CHANGED
@@ -1,12 +1,13 @@
1
1
  # @h-ai/vecdb
2
2
 
3
- 向量数据库模块,通过统一的 `vecdb` 对象访问 LanceDB、pgvector、Qdrant。
3
+ 向量数据库模块,通过统一的 `vecdb` 对象访问 LanceDB、pgvector、Qdrant、Chroma。
4
4
 
5
5
  ## 支持的向量数据库
6
6
 
7
7
  - LanceDB(嵌入式,本地文件存储,零配置)
8
8
  - pgvector(PostgreSQL + pgvector 扩展)
9
9
  - Qdrant(高性能向量搜索引擎)
10
+ - Chroma(支持嵌入式自动拉起本地服务,或直连已有服务)
10
11
 
11
12
  ## 快速开始
12
13
 
@@ -62,8 +63,18 @@ await vecdb.init({
62
63
 
63
64
  // Qdrant
64
65
  await vecdb.init({ type: 'qdrant', url: 'http://localhost:6333', apiKey: 'optional-key' })
66
+
67
+ // Chroma(嵌入式:自动拉起本地 `chroma run` 服务并持久化到 path)
68
+ await vecdb.init({ type: 'chroma', path: './data/chroma' })
69
+
70
+ // Chroma(直连已有服务,不拉起进程)
71
+ await vecdb.init({ type: 'chroma', url: 'http://localhost:8000' })
65
72
  ```
66
73
 
74
+ > Chroma 在 Node 端只有 HTTP 客户端(无进程内嵌入式)。嵌入式模式下 `vecdb.init` 会
75
+ > 通过 `serverCommand`(默认 `chroma`,来自 `chromadb` 包)拉起本地服务,`vecdb.close`
76
+ > 时关闭进程。需安装可选依赖 `chromadb`;服务命令不可用时 `init` 返回 `CONNECTION_FAILED`。
77
+
67
78
  ### 操作日志
68
79
 
69
80
  可在向量数据库配置中通过 `operationLog` 开启操作日志。日志在集合/向量操作进入真实 Provider 前输出,不在 `vecdb-main.ts` 中做统一包装。
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { HaiResult } from '@h-ai/core';
6
6
  * @h-ai/vecdb — 向量数据库配置 Schema
7
7
  *
8
8
  * 本文件定义向量数据库模块的错误码常量、Zod Schema 和配置类型。
9
- * 支持 LanceDB(默认)、pgvector、Qdrant 三种后端。
9
+ * 支持 LanceDB(默认)、pgvector、Qdrant、Chroma 四种后端。
10
10
  * @module vecdb-config
11
11
  */
12
12
 
@@ -17,9 +17,10 @@ import { HaiResult } from '@h-ai/core';
17
17
  * - `lancedb` — LanceDB 嵌入式向量数据库(默认)
18
18
  * - `pgvector` — PostgreSQL + pgvector 扩展
19
19
  * - `qdrant` — Qdrant 向量搜索引擎
20
+ * - `chroma` — Chroma 向量数据库(支持嵌入式自动拉起本地服务)
20
21
  */
21
22
  /** 向量数据库类型 */
22
- type VecdbType = 'lancedb' | 'pgvector' | 'qdrant';
23
+ type VecdbType = 'lancedb' | 'pgvector' | 'qdrant' | 'chroma';
23
24
  /**
24
25
  * 距离度量类型
25
26
  *
@@ -154,6 +155,50 @@ declare const QdrantConfigSchema: z.ZodObject<{
154
155
  }, z.core.$strip>;
155
156
  /** Qdrant 配置类型 */
156
157
  type QdrantConfig = z.infer<typeof QdrantConfigSchema>;
158
+ /**
159
+ * Chroma 配置 Schema
160
+ *
161
+ * Chroma 在 Node 端只有 HTTP 客户端(无进程内嵌入式)。本 Provider 支持两种模式:
162
+ * - **嵌入式**:提供 `path` 且不提供 `url` 时,init 自动拉起本地 `chroma run` 服务
163
+ * (持久化到 `path`),close 时关闭;数据落地本地目录,无需手动启动服务。
164
+ * - **直连**:提供 `url`(或已运行的 host:port)时,直接连接已有 Chroma 服务,不拉起进程。
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * // 嵌入式(自动拉起本地服务)
169
+ * { type: 'chroma', path: './data/chroma' }
170
+ *
171
+ * // 直连已有服务
172
+ * { type: 'chroma', url: 'http://localhost:8000' }
173
+ * ```
174
+ */
175
+ declare const ChromaConfigSchema: z.ZodObject<{
176
+ operationLog: z.ZodOptional<z.ZodObject<{
177
+ read: z.ZodDefault<z.ZodBoolean>;
178
+ write: z.ZodDefault<z.ZodBoolean>;
179
+ maxLength: z.ZodDefault<z.ZodNumber>;
180
+ level: z.ZodDefault<z.ZodEnum<{
181
+ info: "info";
182
+ debug: "debug";
183
+ trace: "trace";
184
+ }>>;
185
+ }, z.core.$strip>>;
186
+ type: z.ZodLiteral<"chroma">;
187
+ path: z.ZodOptional<z.ZodString>;
188
+ url: z.ZodOptional<z.ZodString>;
189
+ host: z.ZodDefault<z.ZodString>;
190
+ port: z.ZodDefault<z.ZodNumber>;
191
+ apiKey: z.ZodOptional<z.ZodString>;
192
+ serverCommand: z.ZodDefault<z.ZodString>;
193
+ startupTimeout: z.ZodDefault<z.ZodNumber>;
194
+ metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
195
+ cosine: "cosine";
196
+ euclidean: "euclidean";
197
+ dot: "dot";
198
+ }>>>;
199
+ }, z.core.$strip>;
200
+ /** Chroma 配置类型 */
201
+ type ChromaConfig = z.infer<typeof ChromaConfigSchema>;
157
202
  /**
158
203
  * 统一向量数据库配置 Schema(判别联合体)
159
204
  *
@@ -224,6 +269,30 @@ declare const VecdbConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
224
269
  euclidean: "euclidean";
225
270
  dot: "dot";
226
271
  }>>>;
272
+ }, z.core.$strip>, z.ZodObject<{
273
+ operationLog: z.ZodOptional<z.ZodObject<{
274
+ read: z.ZodDefault<z.ZodBoolean>;
275
+ write: z.ZodDefault<z.ZodBoolean>;
276
+ maxLength: z.ZodDefault<z.ZodNumber>;
277
+ level: z.ZodDefault<z.ZodEnum<{
278
+ info: "info";
279
+ debug: "debug";
280
+ trace: "trace";
281
+ }>>;
282
+ }, z.core.$strip>>;
283
+ type: z.ZodLiteral<"chroma">;
284
+ path: z.ZodOptional<z.ZodString>;
285
+ url: z.ZodOptional<z.ZodString>;
286
+ host: z.ZodDefault<z.ZodString>;
287
+ port: z.ZodDefault<z.ZodNumber>;
288
+ apiKey: z.ZodOptional<z.ZodString>;
289
+ serverCommand: z.ZodDefault<z.ZodString>;
290
+ startupTimeout: z.ZodDefault<z.ZodNumber>;
291
+ metric: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
292
+ cosine: "cosine";
293
+ euclidean: "euclidean";
294
+ dot: "dot";
295
+ }>>>;
227
296
  }, z.core.$strip>], "type">;
228
297
  /** 向量数据库配置类型(判别联合体) */
229
298
  type VecdbConfig = z.infer<typeof VecdbConfigSchema>;
@@ -508,6 +577,13 @@ interface VecdbFunctions {
508
577
  close: () => Promise<HaiResult<void>>;
509
578
  /** 当前脱敏配置快照(未初始化时为 null) */
510
579
  readonly config: VecdbConfig | null;
580
+ /**
581
+ * 获取底层后端的原始连接信息(含凭证,未初始化时为 null)
582
+ *
583
+ * 供需要直连同一向量库的外部引擎(如 mem0 OSS)复用后端。返回值包含未脱敏的凭证,
584
+ * 仅供同进程内集成使用,禁止写入日志或返回给外部调用方。
585
+ */
586
+ readonly rawConnection: VecdbConnection | null;
511
587
  /** 是否已初始化 */
512
588
  readonly isInitialized: boolean;
513
589
  /** 集合管理操作 */
@@ -515,6 +591,33 @@ interface VecdbFunctions {
515
591
  /** 向量操作 */
516
592
  readonly vector: VectorOperations;
517
593
  }
594
+ /**
595
+ * 向量库原始连接信息
596
+ *
597
+ * 由 `vecdb.rawConnection` 暴露,字段按后端类型填充。包含凭证,仅供同进程内集成使用。
598
+ */
599
+ interface VecdbConnection {
600
+ /** 后端类型 */
601
+ type: VecdbConfig['type'];
602
+ /** 服务 URL(qdrant) */
603
+ url?: string;
604
+ /** API Key(qdrant) */
605
+ apiKey?: string;
606
+ /** 主机(pgvector) */
607
+ host?: string;
608
+ /** 端口(pgvector) */
609
+ port?: number;
610
+ /** 数据库名(pgvector) */
611
+ database?: string;
612
+ /** 用户名(pgvector) */
613
+ user?: string;
614
+ /** 密码(pgvector) */
615
+ password?: string;
616
+ /** 连接串(pgvector) */
617
+ connectionString?: string;
618
+ /** 本地路径(lancedb) */
619
+ path?: string;
620
+ }
518
621
 
519
622
  /**
520
623
  * @h-ai/vecdb — 向量数据库服务主入口
@@ -558,4 +661,4 @@ interface VecdbFunctions {
558
661
  */
559
662
  declare const vecdb: VecdbFunctions;
560
663
 
561
- export { type CollectionCreateOptions, type CollectionInfo, type CollectionOperations, type DistanceMetric, DistanceMetricSchema, HaiVecdbError, type LancedbConfig, type PgvectorConfig, type QdrantConfig, type VecdbConfig, type VecdbConfigInput, VecdbConfigSchema, type VecdbFunctions, type VecdbOperationLogConfig, VecdbOperationLogConfigSchema, type VecdbType, type VectorDocument, type VectorOperations, type VectorSearchOptions, type VectorSearchResult, vecdb };
664
+ export { type ChromaConfig, type CollectionCreateOptions, type CollectionInfo, type CollectionOperations, type DistanceMetric, DistanceMetricSchema, HaiVecdbError, type LancedbConfig, type PgvectorConfig, type QdrantConfig, type VecdbConfig, type VecdbConfigInput, VecdbConfigSchema, type VecdbConnection, type VecdbFunctions, type VecdbOperationLogConfig, VecdbOperationLogConfigSchema, type VecdbType, type VectorDocument, type VectorOperations, type VectorSearchOptions, type VectorSearchResult, vecdb };