UNPKG

@prexo/ai-chat-sdk

Version:

AI Chat Component with Persistent History

32 lines (31 loc) 816 B
import { Index } from "@upstash/vector"; import { VectorDB } from "./vector-db.js"; class ExtVector { vectorDB; namespace; constructor(config, namespace) { const index = new Index({ url: config.url, token: config.token }); this.vectorDB = new VectorDB(index); this.namespace = namespace; } async addContext(input) { if (!input.options) input.options = {}; input.options.namespace = this.namespace; return this.vectorDB.save(input); } async removeContext(ids) { await this.vectorDB.delete({ ids, namespace: this.namespace }); } async getContext(payload) { return this.vectorDB.retrieve({ ...payload, namespace: this.namespace }); } async resetContext() { await this.vectorDB.reset({ namespace: this.namespace }); } } export { ExtVector };