Skip to content

Commit

Permalink
improve searching by vector
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-takei committed Aug 28, 2024
1 parent b2b807a commit aadb14d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions apps/app/src/server/service/search-delegator/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
script_score: {
query: { ...query.body.query },
script: {
source: "cosineSimilarity(params.query_vector, doc['body_embedded']) + 1.0",
source: "cosineSimilarity(params.query_vector, 'body_embedded') + 1.0",
params: { query_vector: queryVector },
},
},
Expand Down Expand Up @@ -893,21 +893,21 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
const order = option?.order ?? null;

const query = this.createSearchQuery();
this.appendCriteriaForQueryString(query, terms);

await this.filterPagesByViewer(query, user, userGroups);

this.appendResultSize(query, from, size);

this.appendSortOrder(query, sort, order);

if (option?.vector) {
await this.filterPagesByViewer(query, user, userGroups);
await this.appendVectorScore(query, queryString, user.username);
}
else {
this.appendCriteriaForQueryString(query, terms);
await this.filterPagesByViewer(query, user, userGroups);
await this.appendFunctionScore(query, queryString);
}

this.appendResultSize(query, from, size);

this.appendSortOrder(query, sort, order);

this.appendHighlight(query);

return this.searchKeyword(query);
Expand Down

0 comments on commit aadb14d

Please sign in to comment.