UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

69 lines (68 loc) 1.85 kB
/** * VectorStore — 向量存储抽象层 * 定义向量存储的标准接口,支持 JSON/Milvus 等后端 */ import { ioLimit } from '#shared/concurrency.js'; export class VectorStore { /** 初始化存储 */ async init() { throw new Error('Not implemented: init()'); } /** * 插入或更新文档 * @param item */ async upsert(item) { throw new Error('Not implemented: upsert()'); } /** 批量 upsert */ async batchUpsert(items) { // p-limit 控制并发,避免批量 upsert 时 OOM 或 DB 锁竞争 await Promise.all(items.map((item) => ioLimit(() => this.upsert(item)))); } /** 删除文档 */ async remove(id) { throw new Error('Not implemented: remove()'); } /** 按 ID 获取 */ async getById(id) { throw new Error('Not implemented: getById()'); } /** * 向量相似度搜索 * @param options { topK, filter, minScore } * @returns >>} */ async searchVector(queryVector, options = {}) { throw new Error('Not implemented: searchVector()'); } /** * 按过滤条件搜索 * @param filter { type, category, language, tags, ... } */ async searchByFilter(filter) { throw new Error('Not implemented: searchByFilter()'); } /** 列出所有 ID */ async listIds() { throw new Error('Not implemented: listIds()'); } /** 清空存储 */ async clear() { throw new Error('Not implemented: clear()'); } /** * 获取统计信息 * @returns >} */ async getStats() { throw new Error('Not implemented: getStats()'); } /** * 销毁: 释放资源, 清理定时器等 * 子类可选实现; 默认无操作 */ destroy() { // no-op by default } }