Skip to content

Commit

Permalink
List all files in a markdown note (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
logancyang authored Dec 1, 2024
1 parent 1d8b4ed commit 53dcdf2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/VectorStoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Embeddings } from "@langchain/core/embeddings";
import { create, load, Orama, remove, removeMultiple, save, search } from "@orama/orama";
import { MD5 } from "crypto-js";
import { App, Notice, Platform, TAbstractFile, TFile, Vault } from "obsidian";
import { getChainType } from "./aiParams";
import { ChainType } from "./chainFactory";
import { VAULT_VECTOR_STORE_STRATEGY } from "./constants";
import { getChainType } from "./aiParams";

class VectorStoreManager {
private app: App;
Expand Down Expand Up @@ -829,7 +829,7 @@ class VectorStoreManager {
// Search all documents and get unique file paths
const result = await search(this.oramaDb, {
term: "",
limit: 10000, // Adjust this limit based on your needs
limit: 100000,
});

// Use a Set to get unique file paths since multiple chunks can belong to the same file
Expand Down
26 changes: 23 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BrevilabsClient } from "@/LLMProviders/brevilabsClient";
import { encryptAllKeys } from "@/encryptionService";
import ChainManager from "@/LLMProviders/chainManager";
import VectorStoreManager from "@/VectorStoreManager";
import { CustomModel } from "@/aiParams";
Expand All @@ -8,13 +7,13 @@ import { registerBuiltInCommands } from "@/commands";
import CopilotView from "@/components/CopilotView";
import { AddPromptModal } from "@/components/modals/AddPromptModal";
import { AdhocPromptModal } from "@/components/modals/AdhocPromptModal";
import { IndexedFilesModal } from "@/components/modals/IndexedFilesModal";
import { ListPromptModal } from "@/components/modals/ListPromptModal";
import { LoadChatHistoryModal } from "@/components/modals/LoadChatHistoryModal";
import { OramaSearchModal } from "@/components/modals/OramaSearchModal";
import { SimilarNotesModal } from "@/components/modals/SimilarNotesModal";
import { CHAT_VIEWTYPE, CHUNK_SIZE, DEFAULT_OPEN_AREA, EVENT_NAMES } from "@/constants";
import { CustomPromptProcessor } from "@/customPromptProcessor";
import { encryptAllKeys } from "@/encryptionService";
import { CustomError } from "@/error";
import { HybridRetriever } from "@/search/hybridRetriever";
import { CopilotSettingTab } from "@/settings/SettingsPage";
Expand Down Expand Up @@ -338,7 +337,28 @@ export default class CopilotPlugin extends Plugin {
new Notice("No indexed files found.");
return;
}
new IndexedFilesModal(this.app, indexedFiles).open();

// Create content for the new file
const content = [
"# Copilot Indexed Files",
`Total files indexed: ${indexedFiles.length}`,
"",
"## Files",
...indexedFiles.map((file) => `- [[${file}]]`),
].join("\n");

// Create the file in the vault
const fileName = `Copilot-Indexed-Files-${new Date().toLocaleDateString().replace(/\//g, "-")}.md`;
const filePath = `${fileName}`;

await this.app.vault.create(filePath, content);

// Open the newly created file
const createdFile = this.app.vault.getAbstractFileByPath(filePath);
if (createdFile instanceof TFile) {
await this.app.workspace.getLeaf().openFile(createdFile);
new Notice(`Created list of ${indexedFiles.length} indexed files`);
}
} catch (error) {
console.error("Error listing indexed files:", error);
new Notice("Failed to list indexed files.");
Expand Down

0 comments on commit 53dcdf2

Please sign in to comment.