MCPcopy Create free account
hub / github.com/OpenAnonymity/oa-chat / openVectorDatabase

Function openVectorDatabase

vector/idbStore.js:22–42  ·  view source on GitHub ↗
(dbName)

Source from the content-addressed store, hash-verified

20}
21
22export 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
44export async function ensureVectorMeta(db, collection, { dimension, metric, normalize }) {
45 const tx = db.transaction([META_STORE], 'readwrite');

Callers 2

initMethod · 0.90
initMethod · 0.90

Calls 2

requestToPromiseFunction · 0.85
openMethod · 0.45

Tested by

no test coverage detected