Add semantic cache support using ChromaDB #3
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user