UNPKG

@propickler/localvectordb

Version:

A lightweight local vector database implementation in Node.js similar to ChromaDB

39 lines (31 loc) 948 B
const Collection = require('./collection'); class VectorDB { constructor() { this.collections = new Map(); } async createCollection(name, dimension) { if (this.collections.has(name)) { throw new Error(`Collection ${name} already exists`); } const collection = new Collection(name, dimension); this.collections.set(name, collection); return collection; } getCollection(name) { const collection = this.collections.get(name); if (!collection) { throw new Error(`Collection ${name} not found`); } return collection; } listCollections() { return Array.from(this.collections.keys()); } deleteCollection(name) { if (!this.collections.has(name)) { throw new Error(`Collection ${name} not found`); } this.collections.delete(name); } } module.exports = VectorDB;