UNPKG

vecstore-js

Version:

A pluggable, browser-native vector database using IndexedDB with support for HNSW and local embeddings.

25 lines (24 loc) 655 B
import { openDB } from 'idb'; export class IDBStorageAdapter { constructor(dbName) { this.dbName = dbName; this.dbPromise = this.init(); } async init() { return openDB(this.dbName, 1, { upgrade(db) { if (!db.objectStoreNames.contains('documents')) { db.createObjectStore('documents', { keyPath: 'id' }); } } }); } async put(doc) { const db = await this.dbPromise; await db.put('documents', doc); } async getAll() { const db = await this.dbPromise; return db.getAll('documents'); } }