(dbName)
| 20 | } |
| 21 | |
| 22 | export async function openVectorDatabase(dbName) { |
| 23 | if (typeof indexedDB === 'undefined') { |
| 24 | throw new Error('IndexedDB is not available in this environment.'); |
| 25 | } |
| 26 | |
| 27 | const request = indexedDB.open(dbName, DB_VERSION); |
| 28 | request.onupgradeneeded = (event) => { |
| 29 | const db = event.target.result; |
| 30 | |
| 31 | if (!db.objectStoreNames.contains(ITEMS_STORE)) { |
| 32 | const store = db.createObjectStore(ITEMS_STORE, { keyPath: 'key' }); |
| 33 | store.createIndex('collection', 'collection', { unique: false }); |
| 34 | } |
| 35 | |
| 36 | if (!db.objectStoreNames.contains(META_STORE)) { |
| 37 | db.createObjectStore(META_STORE, { keyPath: 'collection' }); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | return requestToPromise(request); |
| 42 | } |
| 43 | |
| 44 | export async function ensureVectorMeta(db, collection, { dimension, metric, normalize }) { |
| 45 | const tx = db.transaction([META_STORE], 'readwrite'); |
no test coverage detected