Integrate semantic cache with ChromaDB URL

This commit is contained in:
2026-05-07 21:34:19 +02:00
parent b37aaeb4d4
commit 96d7323377
9 changed files with 223 additions and 63 deletions
+71 -1
View File
@@ -49,7 +49,11 @@ export default class OllamaPlugin extends Plugin {
const data = (await this.loadData()) as Partial<PluginSettings> | null;
if (data) {
Logger.debug('Loading saved settings', 'settings');
this.settings = Object.assign({}, this.settings, data);
this.settings = {
...DEFAULT_SETTINGS,
...data,
cacheConfig: { ...DEFAULT_SETTINGS.cacheConfig, ...data.cacheConfig },
};
}
} catch (error) {
ErrorHandler.handleError(error, 'settings load');
@@ -89,6 +93,17 @@ export default class OllamaPlugin extends Plugin {
}
});
}
public async clearSemanticCache(): Promise<void> {
const leaves = this.app.workspace.getLeavesOfType('ollama-chat-view');
for (const leaf of leaves) {
const view = leaf.view;
if (view instanceof ChatView) {
await view.clearCache();
return;
}
}
}
}
class OllamaSettingTab extends PluginSettingTab {
@@ -152,6 +167,61 @@ class OllamaSettingTab extends PluginSettingTab {
this.plugin.notifyChatViews();
})
);
new Setting(container)
.setName('ChromaDB URL')
.setDesc('URL of your ChromaDB instance (used for semantic cache)')
.addText((text) =>
text.setValue(this.plugin.settings.cacheConfig.chromaUrl).onChange(async (value) => {
this.plugin.settings.cacheConfig.chromaUrl = value;
await this.plugin.saveSettings();
this.plugin.notifyChatViews();
})
);
new Setting(container)
.setName('Cache Embedding Model')
.setDesc('Ollama model used to generate embeddings for the semantic cache')
.addText((text) =>
text.setValue(this.plugin.settings.cacheConfig.embeddingModel).onChange(async (value) => {
this.plugin.settings.cacheConfig.embeddingModel = value;
await this.plugin.saveSettings();
this.plugin.notifyChatViews();
})
);
new Setting(container)
.setName('Cache Similarity Threshold')
.setDesc(
'Minimum cosine similarity (01) for a cache hit. Higher values require closer matches.'
)
.addText((text) =>
text
.setValue(String(this.plugin.settings.cacheConfig.similarityThreshold))
.onChange(async (value) => {
const parsed = parseFloat(value);
if (!isNaN(parsed) && parsed >= 0 && parsed <= 1) {
this.plugin.settings.cacheConfig.similarityThreshold = parsed;
await this.plugin.saveSettings();
} else {
new Notice('Similarity threshold must be a number between 0 and 1.');
}
})
);
new Setting(container)
.setName('Clear Semantic Cache')
.setDesc('Delete all cached responses from ChromaDB')
.addButton((button) =>
button.setButtonText('Clear Cache').onClick(async () => {
try {
await this.plugin.clearSemanticCache();
new Notice('Semantic cache cleared.');
} catch {
new Notice('Failed to clear semantic cache. Is ChromaDB running?');
}
})
);
}
hide(): void {