mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2025-06-30 12:44:18 +03:00
Add setting to exclude copilot index in obsidian sync (#908)
This commit is contained in:
@ -35,8 +35,6 @@ class VectorStoreManager {
|
||||
|
||||
constructor(app: App) {
|
||||
this.app = app;
|
||||
|
||||
this.dbPath = this.getDbPath();
|
||||
this.embeddingsManager = EmbeddingsManager.getInstance();
|
||||
|
||||
// Initialize the database asynchronously
|
||||
@ -89,8 +87,21 @@ class VectorStoreManager {
|
||||
}
|
||||
}
|
||||
|
||||
private getDbPath(): string {
|
||||
return `${this.app.vault.configDir}/copilot-index-${this.getVaultIdentifier()}.json`;
|
||||
private async getDbPath(): Promise<string> {
|
||||
if (getSettings().enableIndexSync) {
|
||||
return `${this.app.vault.configDir}/copilot-index-${this.getVaultIdentifier()}.json`;
|
||||
}
|
||||
|
||||
// Get vault root path (parent of .obsidian directory)
|
||||
const vaultRoot = this.app.vault.getRoot().path;
|
||||
const indexDir = `${vaultRoot}/.copilot-index`;
|
||||
|
||||
// Create .copilot-index directory if it doesn't exist
|
||||
if (!(await this.app.vault.adapter.exists(indexDir))) {
|
||||
await this.app.vault.adapter.mkdir(indexDir);
|
||||
}
|
||||
|
||||
return `${indexDir}/copilot-index-${this.getVaultIdentifier()}.json`;
|
||||
}
|
||||
|
||||
private createDynamicSchema(vectorLength: number) {
|
||||
@ -118,7 +129,7 @@ class VectorStoreManager {
|
||||
return;
|
||||
}
|
||||
|
||||
this.dbPath = this.getDbPath();
|
||||
this.dbPath = await this.getDbPath();
|
||||
// Ensure the config directory exists
|
||||
const configDir = this.app.vault.configDir;
|
||||
if (!(await this.app.vault.adapter.exists(configDir))) {
|
||||
@ -244,6 +255,13 @@ class VectorStoreManager {
|
||||
...rawData,
|
||||
};
|
||||
|
||||
// Ensure the directory exists before saving
|
||||
const dbDir = this.dbPath.substring(0, this.dbPath.lastIndexOf("/"));
|
||||
|
||||
if (!(await this.app.vault.adapter.exists(dbDir))) {
|
||||
await this.app.vault.adapter.mkdir(dbDir);
|
||||
}
|
||||
|
||||
// Use requestIdleCallback if available, otherwise use setTimeout
|
||||
const saveOperation = async () => {
|
||||
try {
|
||||
|
@ -251,6 +251,7 @@ export const DEFAULT_SETTINGS: CopilotSettings = {
|
||||
qaInclusions: "",
|
||||
chatNoteContextPath: "",
|
||||
chatNoteContextTags: [],
|
||||
enableIndexSync: true,
|
||||
debug: false,
|
||||
enableEncryption: false,
|
||||
maxSourceChunks: 3,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { CustomModel } from "@/aiParams";
|
||||
import { EmbeddingModelProviders, VAULT_VECTOR_STORE_STRATEGIES } from "@/constants";
|
||||
import { updateSetting, useSettingsValue } from "@/settings/model";
|
||||
import React from "react";
|
||||
import {
|
||||
DropdownComponent,
|
||||
@ -8,7 +9,6 @@ import {
|
||||
TextAreaComponent,
|
||||
ToggleComponent,
|
||||
} from "./SettingBlocks";
|
||||
import { updateSetting, useSettingsValue } from "@/settings/model";
|
||||
|
||||
const QASettings: React.FC = () => {
|
||||
const settings = useSettingsValue();
|
||||
@ -23,7 +23,7 @@ const QASettings: React.FC = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="copilot-settings-tab">
|
||||
<h1>QA Settings</h1>
|
||||
<p>
|
||||
QA mode relies on a <em>local</em> vector index.
|
||||
@ -123,6 +123,12 @@ const QASettings: React.FC = () => {
|
||||
value={settings.qaInclusions}
|
||||
onChange={(value) => updateSetting("qaInclusions", value)}
|
||||
/>
|
||||
<ToggleComponent
|
||||
name="Enable Obsidian Sync for Copilot index"
|
||||
description="If enabled, the index will be stored in the .obsidian folder and synced with Obsidian Sync by default. If disabled, it will be stored in .copilot-index folder at vault root."
|
||||
value={settings.enableIndexSync}
|
||||
onChange={(value) => updateSetting("enableIndexSync", value)}
|
||||
/>
|
||||
<ToggleComponent
|
||||
name="Disable index loading on mobile"
|
||||
description="When enabled, Copilot index won't be loaded on mobile devices to save resources. Only chat mode will be available. Any existing index from desktop sync will be preserved. Uncheck to enable QA modes on mobile."
|
||||
|
@ -42,6 +42,7 @@ export interface CopilotSettings {
|
||||
indexVaultToVectorStore: string;
|
||||
chatNoteContextPath: string;
|
||||
chatNoteContextTags: string[];
|
||||
enableIndexSync: boolean;
|
||||
debug: boolean;
|
||||
enableEncryption: boolean;
|
||||
maxSourceChunks: number;
|
||||
|
Reference in New Issue
Block a user