hnswsqlite
Version:
Vector search with HNSWlib and SQLite in TypeScript.
28 lines (22 loc) • 891 B
text/typescript
import { VectorStore } from '../../vectorStore';
export async function deleteDocument(store: VectorStore, id: number): Promise<boolean> {
return store.deleteDocument(id);
}
export async function listDocuments(store: VectorStore): Promise<Array<{id: number, text: string}>> {
// This is a simplified implementation that gets all documents
// In a real app, you'd want pagination for large datasets
const results = [];
// This is a workaround since we don't have a direct method to list all documents
// In a real app, you'd add a method to VectorStore to get all documents
const allIds = store['idMap'];
for (const id of allIds) {
const doc = await store['preparedStatements'].getDocument.get(id) as { id: number, text: string } | undefined;
if (doc) {
results.push({
id: doc.id,
text: doc.text
});
}
}
return results;
}