Skip to content

Commit

Permalink
increase cosine similarity threshold to 0.55
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed May 7, 2024
1 parent a7760f1 commit 994e66b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/api/src/entity/library_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ export class LibraryItem {
@Column('text')
readableContent!: string

// typeorm does not support vector type, so we store it as a string
@Column('text')
embedding?: number[]
embedding?: string

@Column('text', { nullable: true })
textContentHash?: string | null
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/jobs/ai/update_embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const updateEmbedding = async (data: UpdateEmbeddingJobData) => {

await updateLibraryItem(
libraryItemId,
{ embedding: `[${embedding.toString()}]` },
{ embedding: JSON.stringify(embedding) },
userId,
undefined,
true
Expand Down
14 changes: 8 additions & 6 deletions packages/api/src/jobs/save_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ export const savePageJob = async (data: Data, attemptsMade: number) => {
throw new Error(result.message || result.errorCodes[0])
}

await enqueueUpdateEmbedding({
libraryItemId: result.clientRequestId,
userId,
})
if (result.__typename === 'SaveSuccess') {
await enqueueUpdateEmbedding({
libraryItemId: result.clientRequestId,
userId,
})

isImported = true
isSaved = true
isImported = true
isSaved = true
}
} catch (e) {
logError(e)

Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/queue-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { env } from './env'
import { TaskState } from './generated/graphql'
import { aiSummarize, AI_SUMMARIZE_JOB_NAME } from './jobs/ai-summarize'
import { createDigest, CREATE_DIGEST_JOB } from './jobs/ai/create_digest'
import { UDPATE_EMBEDDING_JOB_NAME, updateEmbedding } from './jobs/ai/update_embedding'
import {
UDPATE_EMBEDDING_JOB_NAME,
updateEmbedding,
} from './jobs/ai/update_embedding'
import { bulkAction, BULK_ACTION_JOB_NAME } from './jobs/bulk_action'
import { callWebhook, CALL_WEBHOOK_JOB_NAME } from './jobs/call_webhook'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/services/library_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export const buildQueryString = (

orders.push({ by: alias, order: SortOrder.DESCENDING })

return escapeQueryWithParameters(`${similarity} > 0.5`, {
return escapeQueryWithParameters(`${similarity} > 0.55`, {
[param]: value,
})
}
Expand Down

0 comments on commit 994e66b

Please sign in to comment.