UNPKG

closevector-web

Version:

CloseVector is fundamentally a vector database. We have made dedicated libraries available for both browsers and node.js, aiming for easy integration no matter your platform. One feature we've been working on is its potential for scalability. Instead of b

85 lines (84 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CloseVectorManager = void 0; const hnswlibWasm_1 = require("./hnswlibWasm"); const loader_1 = require("./loader"); const lib_1 = require("./lib"); const embeddings_1 = require("./embeddings"); class CloseVectorManager { accessKey; uuid; customEmbeddings; lib = null; urlCreator = null; onProgress = null; constructor(options) { const { accessKey, uuid, customEmbeddings } = options; this.accessKey = accessKey; this.uuid = uuid; this.customEmbeddings = customEmbeddings; this.onProgress = options.onProgress || null; this.urlCreator = options.fileUrlCreator || null; if (!this.urlCreator) { this.urlCreator = async () => { if (!this.uuid || !this.accessKey) { throw new Error("uuid and accessKey are required"); } let resp = await (0, lib_1.createPublicGetFileOperationUrl)({ uuid: this.uuid, accessKey: this.accessKey }); return resp.url; }; } if (!this.customEmbeddings) { if (!this.accessKey) { throw new Error("accessKey is required when customEmbeddings is not provided"); } this.customEmbeddings = new embeddings_1.CloseVectorFreeEmbeddings({ key: this.accessKey }); } } async loadFromCloud() { if (!this.accessKey || !this.uuid) { throw new Error("uuid and accessKey are required"); } if (!this.customEmbeddings) { throw new Error("customEmbeddings is required"); } if (!this.urlCreator) { throw new Error("urlCreator is required"); } const url = await this.urlCreator(); await (0, loader_1.download)({ url, onProgress: this.onProgress || undefined, }); const lib = await hnswlibWasm_1.CloseVectorHNSWWeb.load(`${this.uuid}.hnsw`, this.customEmbeddings); return lib; } async createNewCloseVector(args) { if (!this.customEmbeddings) { throw new Error("customEmbeddings is required"); } if (!args.space) { args.space = 'cosine'; } const lib = new hnswlibWasm_1.CloseVectorHNSWWeb(this.customEmbeddings, args); return lib; } async fromDocuments(documents) { if (!this.customEmbeddings) { throw new Error("customEmbeddings is required"); } let lib = await hnswlibWasm_1.CloseVectorHNSWWeb.fromDocuments(documents, this.customEmbeddings); this.lib = lib; } async fromTexts(texts, metadatas) { if (!this.customEmbeddings) { throw new Error("customEmbeddings is required"); } let lib = await hnswlibWasm_1.CloseVectorHNSWWeb.fromTexts(texts, metadatas, this.customEmbeddings); this.lib = lib; } } exports.CloseVectorManager = CloseVectorManager;