Skip to content

Commit

Permalink
2.18.9: fix: Links without saving data
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Mar 19, 2023
1 parent ddc6a97 commit 4b78b4c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "ava",
"name": "🧙 AVA",
"version": "2.18.8",
"version": "2.18.9",
"minAppVersion": "0.12.0",
"description": "AI assistant for Obsidian",
"author": "louis030195",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ava",
"version": "2.18.8",
"version": "2.18.9",
"description": "AI assistant for Obsidian",
"main": "main.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/LinkComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ const ControlForm = () => {
if (data.useNoteTitle) {
query['path'] = state.currentFilePath;
}
const stringified = prepareFilesToEmbed([
const newQuery = prepareFilesToEmbed([
query,
])[0];

console.log('Search query:', stringified);
console.log('Search query:', newQuery);

const response = await fetch(`${state.settings.embedbaseUrl}/v1/${state.settings.vaultId}/search`, {
method: 'POST',
Expand All @@ -124,15 +124,15 @@ const ControlForm = () => {
'X-Client-Version': state.version,
},
body: JSON.stringify({
query: stringified,
query: JSON.stringify(newQuery),
top_k: Number(data.limit),
}),
}).then((res) => res.json());

response.similarities = response.similarities.map((similarity: any) => ({
// parse the JSON data into {path, content}
...JSON.parse(similarity.data),
...JSON.parse(similarity.data || '{}'),
score: similarity.score,
path: similarity.metadata.path,
}));

const embeds = camelize(response.similarities.filter(
Expand Down
8 changes: 4 additions & 4 deletions src/indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export const prepareFilesToEmbed = (files: { path?: string, content: string }[])
markdownEntriesPerFile.push(`${prefix}${entry.trim()}`);
}
}
entries.push(...markdownEntriesPerFile.map((entry) => JSON.stringify((
entries.push(...markdownEntriesPerFile.map((entry) => (
markdownFile.path ?
{ content: entry, path: markdownFile.path } :
{ content: entry }
))));
)));
}
// HACK: atm remove too long entries until we have a better solution
// HACK: atm remove too long header entries until we have a better solution
// to properly index them (either average embeddings or split smartly in the client)
const maxEntryLength = 2000; // should use tokens once tiktoken works on browser
entries = entries.filter((entry) => entry.length < maxEntryLength);
entries = entries.filter((entry) => JSON.stringify(entry).length < maxEntryLength);
// HACK

console.log(`Split ${files.length} files into ${entries.length} entries`);
Expand Down
4 changes: 3 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default class AvaPlugin extends Plugin {
}
return acc;
}, [])
.map((batch: string[]) =>
.map((batch) =>
syncIndex(
batch,
this.settings,
Expand Down Expand Up @@ -304,6 +304,7 @@ export default class AvaPlugin extends Plugin {
this.app.vault.adapter.read(this.lastFile.path).then((data) => {
if (!this.lastFile) return setLastFile(leaf);
syncIndex(
// @ts-ignore
prepareFilesToEmbed([{
path: this.lastFile.path,
content: data,
Expand Down Expand Up @@ -345,6 +346,7 @@ export default class AvaPlugin extends Plugin {
return;
}
syncIndex(
// @ts-ignore
prepareFilesToEmbed([{
path: this.lastFile.path,
content: data,
Expand Down
11 changes: 8 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export const search = async (
console.log('Search response:', response);
response.similarities = response.similarities.map((similarity: any) => ({
// parse the JSON data into {path, content}
...JSON.parse(similarity.data),
...JSON.parse(similarity.data || '{}'),
score: similarity.score,
path: similarity.metadata.path,
}));
return response;
};
Expand All @@ -86,6 +87,7 @@ export const createSemanticLinks = async (
if (!response.similarities) {
return [];
}
console.log('Similarities:', response);
const similarities = response.similarities.filter(
(similarity) =>
similarity.path !== title &&
Expand Down Expand Up @@ -196,7 +198,7 @@ export const deleteFromIndex = async (


export const syncIndex = async (
notes: string[],
notes: {content: string, path: string}[],
settings: AvaSettings,
version: string,
) => {
Expand All @@ -215,7 +217,10 @@ export const syncIndex = async (
headers: buildHeaders(settings.token, version),
body: JSON.stringify({
documents: notes.map((note) => ({
data: note,
data: JSON.stringify(note),
metadata: {
path: note.path,
}
})),
store_data: settings.storeData,
}),
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@
"2.18.5": "0.12.0",
"2.18.6": "0.12.0",
"2.18.7": "0.12.0",
"2.18.8": "0.12.0"
"2.18.8": "0.12.0",
"2.18.9": "0.12.0"
}

0 comments on commit 4b78b4c

Please sign in to comment.