Add semantic cache support using ChromaDB #3

Open
fegger wants to merge 4 commits from feature/semantic_caching into main
4 changed files with 4 additions and 8 deletions
Showing only changes of commit a36a5f1687 - Show all commits
+1 -1
View File
@@ -6,7 +6,7 @@ import { CacheConfig } from './types';
export class SemanticCacheService {
private client: ChromaClient;
private collection: ReturnType<ChromaClient['getOrCreateCollection']> | null = null;
private collection: any | null = null;
private config: CacheConfig;
private ollamaURL: string;
private chromaURL: string;
+1 -1
View File
@@ -37,7 +37,7 @@ const mockSettings: PluginSettings = {
similarityThreshold: 0.9,
collectionName: 'test-cache',
embeddingModel: 'nomic-embed-text',
chromaUrl: 'http://localhost:8000',
chromaURL: 'http://localhost:8000',
},
};
+1 -1
View File
@@ -70,7 +70,7 @@ describe('OllamaClient with Semantic Cache', () => {
similarityThreshold: 0.85,
collectionName: 'test_cache',
embeddingModel: 'nomic-embed-text',
chromaUrl: 'http://localhost:8000',
chromaURL: 'http://localhost:8000',
};
beforeEach(() => {
+1 -5
View File
@@ -54,7 +54,7 @@ describe('SemanticCacheService', () => {
similarityThreshold: 0.85,
collectionName: 'test_cache',
embeddingModel: 'nomic-embed-text',
chromaUrl: 'http://localhost:8000',
chromaURL: 'http://localhost:8000',
};
service = new SemanticCacheService('http://localhost:11434', config);
@@ -273,24 +273,20 @@ describe('SemanticCacheService', () => {
});
});
describe('clearCache', () => {
beforeEach(async () => {
await service.initialize();
mockChromaClient.deleteCollection.mockResolvedValue(undefined);
});
it('should delete the collection and re-initialize', async () => {
await service.clearCache();
expect(mockChromaClient.deleteCollection).toHaveBeenCalledWith({ name: 'test_cache' });
// getOrCreateCollection called once in beforeEach initialize, once in clearCache re-init
expect(mockChromaClient.getOrCreateCollection).toHaveBeenCalledTimes(2);
});
it('should propagate errors from deleteCollection', async () => {
mockChromaClient.deleteCollection.mockRejectedValueOnce(new Error('Delete failed'));
await expect(service.clearCache()).rejects.toThrow('Delete failed');
});
});
});