feat: added tool to get clustered list of notes
This commit is contained in:
parent
6d4bb0c6cb
commit
b7e43dbac0
|
@ -271,3 +271,32 @@ export async function initVectorStoreSync() {
|
|||
export function semantic_search_notes(query: string, limit: number) {
|
||||
return vectorStore.similaritySearch(query, limit);
|
||||
}
|
||||
|
||||
export async function getClusteredFiles(): Promise<Record<string, string[]>> {
|
||||
const result: Record<string, string[]> = {};
|
||||
|
||||
// Query to get filenames and their respective cluster assignments
|
||||
const queryResult = await vectorStore.client?.query(
|
||||
`SELECT ${config.columns.metadataColumnName}->>'filename' AS filename, ${config.columns.clusterColumnName} AS cluster
|
||||
FROM ${config.tableName}`
|
||||
);
|
||||
|
||||
if (!queryResult) {
|
||||
console.log("No clustered files found in the vector store.");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Group filenames by cluster
|
||||
queryResult.rows.forEach((row) => {
|
||||
const clusterName = `Cluster ${row.cluster}`; // Format the cluster name
|
||||
const filename = row.filename;
|
||||
|
||||
if (!result[clusterName]) {
|
||||
result[clusterName] = [];
|
||||
}
|
||||
result[clusterName].push(filename);
|
||||
});
|
||||
|
||||
console.log("Clustered files:", result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,11 @@ import Fuse from "fuse.js";
|
|||
import { ask, get_transcription } from "./ask";
|
||||
import { Message } from "../interfaces/message";
|
||||
import { memory_manager_guide, memory_manager_init } from "./memory-manager";
|
||||
import { semantic_search_notes, syncVectorStore } from "./notes-vectors";
|
||||
import {
|
||||
getClusteredFiles,
|
||||
semantic_search_notes,
|
||||
syncVectorStore,
|
||||
} from "./notes-vectors";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { tmpdir } from "os";
|
||||
|
@ -104,6 +108,21 @@ async function semanticSearchNotes({
|
|||
}
|
||||
}
|
||||
|
||||
const GetClusteredFileListParams = z.object({});
|
||||
type GetClusteredFileListParams = z.infer<typeof GetClusteredFileListParams>;
|
||||
|
||||
export async function getClusteredFileList({}: GetClusteredFileListParams): Promise<OperationResult> {
|
||||
try {
|
||||
const results = await getClusteredFiles();
|
||||
return {
|
||||
success: true,
|
||||
message: JSON.stringify(results, null, 2),
|
||||
};
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to normalize paths
|
||||
function normalizePath(path: string): string {
|
||||
if (path.startsWith("/notes/")) return path.substring(7);
|
||||
|
@ -615,4 +634,12 @@ You can use this to search by:
|
|||
4. Tags
|
||||
`,
|
||||
}),
|
||||
zodFunction({
|
||||
function: getClusteredFileList,
|
||||
name: "getClusteredFileList",
|
||||
schema: GetClusteredFileListParams,
|
||||
description: `Get the list of notes files based on 4 cluster (unsupervised) semantic clustering.
|
||||
You can use this to see how the notes are clustered based on their content.
|
||||
`,
|
||||
}),
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue