Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpetro committed Aug 17, 2024
1 parent 18edf2b commit 4373dae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 43 deletions.
41 changes: 0 additions & 41 deletions src/actions/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*
*/
export async function lookup(env, params={}) {
// TODO
console.log("lookup", params);
const { hypotheticals = [], hypothetical_1, hypothetical_2, hypothetical_3, ...other_params } = params;
if(hypothetical_1) hypotheticals.push(hypothetical_1);
Expand All @@ -35,46 +34,6 @@ export async function lookup(env, params={}) {
if(!hypotheticals) return {error: "hypotheticals is required"};
const collection = env.smart_blocks?.smart_embed ? env.smart_blocks : env.smart_sources;
return await collection.lookup({...(other_params || {}), hypotheticals});
// BELOW LOGIC MOVED TO SmartEntities.lookup()
console.log(collection);
if(!collection || !collection.smart_embed) return {error: "Embedding search is not enabled."};
const embeddings = await collection.smart_embed.embed_batch(hypotheticals.map(h => ({embed_input: h})));
console.log(embeddings);
console.log({scope: env.chats?.current?.scope});
const filter = {
...(env.chats?.current?.scope || {}),
...(params.filter || {}),
};
console.log({filter});
const results = embeddings.flatMap((embedding, i) => {
return collection.nearest(embedding.vec, filter);
});
// console.log(results);
// sort by sim sim desc
results.sort((a, b) => {
if(a.sim === b.sim) return 0;
return (a.sim > b.sim) ? -1 : 1;
});
// get top K results
const k = params.k || env.config.lookup_k || 10;
let top_k = await Promise.all(results.slice(0, k)
// filter duplicates by r.data.path
.filter((r, i, a) => a.findIndex(t => t.data.path === r.data.path) === i)
.map(async r => {
return {
score: r.sim,
path: r.data.path,
};
})
);
// DO: decided whether to use these functions
// console.log("nearest before std dev slice", top_k.length);
// top_k = get_nearest_until_next_dev_exceeds_std_dev(top_k); // tested
// console.log("nearest after std dev slice", top_k.length);
// top_k = sort_by_len_adjusted_similarity(top_k); // tested
console.log(top_k);
console.log(`Found and returned ${top_k.length} ${collection.collection_name}.`);
return top_k;
}

// // IN DEVELOPMENT (Collection.retrieve(strategy, opts))
Expand Down
4 changes: 2 additions & 2 deletions src/sc_smart_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ export class ScSmartView extends SmartObsidianView {
if (!entity) return false;
if (entity.is_canvas) return true;
if (entity.is_excalidraw) return true;
if (entity.note?.is_canvas) return true;
if (entity.note?.is_excalidraw) return true;
if (entity.source?.is_canvas) return true;
if (entity.source?.is_excalidraw) return true;
return false;
}
}
Expand Down

0 comments on commit 4373dae

Please sign in to comment.