2025-02-04 01:30:36 -05:00

71 lines
1.9 KiB
TypeScript

import Store from 'electron-store';
import { DocumentMetadata } from '../types';
const store = new Store<{
documents: Record<string, DocumentMetadata>;
}>();
class VectorStoreService {
private documents: Map<string, DocumentMetadata>;
constructor() {
this.documents = new Map(Object.entries(store.get('documents', {})));
// Add example documents if none exist
if (this.documents.size === 0) {
const examples: DocumentMetadata[] = [
{
path: 'C:/example/llm-only',
type: 'directory',
lastModified: Date.now(),
size: 0,
hasEmbeddings: true,
hasOcr: false
},
{
path: 'C:/example/ocr-only',
type: 'directory',
lastModified: Date.now(),
size: 0,
hasEmbeddings: false,
hasOcr: true
},
{
path: 'C:/example/both-enabled',
type: 'directory',
lastModified: Date.now(),
size: 0,
hasEmbeddings: true,
hasOcr: true
}
];
examples.forEach(doc => {
this.documents.set(doc.path, doc);
});
store.set('documents', Object.fromEntries(this.documents));
}
}
public async addDocument(content: string, metadata: DocumentMetadata): Promise<void> {
// TODO: Implement vector storage
this.documents.set(metadata.path, metadata);
store.set('documents', Object.fromEntries(this.documents));
}
public async deleteDocument(path: string): Promise<void> {
this.documents.delete(path);
store.set('documents', Object.fromEntries(this.documents));
}
public async updateDocument(content: string, metadata: DocumentMetadata): Promise<void> {
await this.addDocument(content, metadata);
}
public getDocuments(): DocumentMetadata[] {
return Array.from(this.documents.values());
}
}
export const vectorStoreService = new VectorStoreService();