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) {
|
constructor(app: App) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
this.dbPath = this.getDbPath();
|
|
||||||
this.embeddingsManager = EmbeddingsManager.getInstance();
|
this.embeddingsManager = EmbeddingsManager.getInstance();
|
||||||
|
|
||||||
// Initialize the database asynchronously
|
// Initialize the database asynchronously
|
||||||
@ -89,8 +87,21 @@ class VectorStoreManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getDbPath(): string {
|
private async getDbPath(): Promise<string> {
|
||||||
return `${this.app.vault.configDir}/copilot-index-${this.getVaultIdentifier()}.json`;
|
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) {
|
private createDynamicSchema(vectorLength: number) {
|
||||||
@ -118,7 +129,7 @@ class VectorStoreManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dbPath = this.getDbPath();
|
this.dbPath = await this.getDbPath();
|
||||||
// Ensure the config directory exists
|
// Ensure the config directory exists
|
||||||
const configDir = this.app.vault.configDir;
|
const configDir = this.app.vault.configDir;
|
||||||
if (!(await this.app.vault.adapter.exists(configDir))) {
|
if (!(await this.app.vault.adapter.exists(configDir))) {
|
||||||
@ -244,6 +255,13 @@ class VectorStoreManager {
|
|||||||
...rawData,
|
...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
|
// Use requestIdleCallback if available, otherwise use setTimeout
|
||||||
const saveOperation = async () => {
|
const saveOperation = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -251,6 +251,7 @@ export const DEFAULT_SETTINGS: CopilotSettings = {
|
|||||||
qaInclusions: "",
|
qaInclusions: "",
|
||||||
chatNoteContextPath: "",
|
chatNoteContextPath: "",
|
||||||
chatNoteContextTags: [],
|
chatNoteContextTags: [],
|
||||||
|
enableIndexSync: true,
|
||||||
debug: false,
|
debug: false,
|
||||||
enableEncryption: false,
|
enableEncryption: false,
|
||||||
maxSourceChunks: 3,
|
maxSourceChunks: 3,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { CustomModel } from "@/aiParams";
|
import { CustomModel } from "@/aiParams";
|
||||||
import { EmbeddingModelProviders, VAULT_VECTOR_STORE_STRATEGIES } from "@/constants";
|
import { EmbeddingModelProviders, VAULT_VECTOR_STORE_STRATEGIES } from "@/constants";
|
||||||
|
import { updateSetting, useSettingsValue } from "@/settings/model";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {
|
import {
|
||||||
DropdownComponent,
|
DropdownComponent,
|
||||||
@ -8,7 +9,6 @@ import {
|
|||||||
TextAreaComponent,
|
TextAreaComponent,
|
||||||
ToggleComponent,
|
ToggleComponent,
|
||||||
} from "./SettingBlocks";
|
} from "./SettingBlocks";
|
||||||
import { updateSetting, useSettingsValue } from "@/settings/model";
|
|
||||||
|
|
||||||
const QASettings: React.FC = () => {
|
const QASettings: React.FC = () => {
|
||||||
const settings = useSettingsValue();
|
const settings = useSettingsValue();
|
||||||
@ -23,7 +23,7 @@ const QASettings: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="copilot-settings-tab">
|
||||||
<h1>QA Settings</h1>
|
<h1>QA Settings</h1>
|
||||||
<p>
|
<p>
|
||||||
QA mode relies on a <em>local</em> vector index.
|
QA mode relies on a <em>local</em> vector index.
|
||||||
@ -123,6 +123,12 @@ const QASettings: React.FC = () => {
|
|||||||
value={settings.qaInclusions}
|
value={settings.qaInclusions}
|
||||||
onChange={(value) => updateSetting("qaInclusions", value)}
|
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
|
<ToggleComponent
|
||||||
name="Disable index loading on mobile"
|
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."
|
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;
|
indexVaultToVectorStore: string;
|
||||||
chatNoteContextPath: string;
|
chatNoteContextPath: string;
|
||||||
chatNoteContextTags: string[];
|
chatNoteContextTags: string[];
|
||||||
|
enableIndexSync: boolean;
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
enableEncryption: boolean;
|
enableEncryption: boolean;
|
||||||
maxSourceChunks: number;
|
maxSourceChunks: number;
|
||||||
|
Reference in New Issue
Block a user