这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@shatfield4
Copy link
Collaborator

resolves #282

• Includes relevancy score with similarityResponse for each vector database provider
• Will be used in the future to display citations based on relevancy score to chat question asked

@shatfield4 shatfield4 linked an issue Oct 28, 2023 that may be closed by this pull request
@review-agent-prime
Copy link

The PR looks good overall, but there are a few areas where improvements can be made:

  1. In the distanceToScore function, you are checking if the distance is a number and if it's null. However, you are not checking if the distance is a negative number. Negative distances might not make sense in this context, so it would be good to add a check for that.
distanceToScore: function (distance = null) {
  if (distance === null || typeof distance !== "number" || distance < 0) return 0.0;
  if (distance >= 1.0) return 1;
  if (distance <= 0) return 0;
  return 1 - distance;
},
  1. In the similarityResponse function, you are pushing the score into the result.scores array. However, you are not checking if the score is a valid number. It would be good to add a check for that.
response.ids[0].forEach((_, i) => {
  result.contextTexts.push(response.documents[0][i]);
  result.sourceDocuments.push(response.metadatas[0][i]);
  const score = this.distanceToScore(response.distances[0][i]);
  if (typeof score === "number" && !isNaN(score)) {
    result.scores.push(score);
  }
});
  1. In the similarityResponse function, you are pushing the score into the result.scores array. However, you are not checking if the score is a valid number. It would be good to add a check for that.
response.forEach((item) => {
  const { vector: _, ...rest } = item;
  result.contextTexts.push(rest.text);
  result.sourceDocuments.push(rest);
  if (typeof item.score === "number" && !isNaN(item.score)) {
    result.scores.push(item.score);
  }
});

Please consider these suggestions and update the PR accordingly.

@timothycarambat timothycarambat merged commit 669d7a3 into master Oct 30, 2023
@timothycarambat timothycarambat deleted the 282-return-relevancy-score-with-similarityresponse branch October 30, 2023 19:46
franzbischoff referenced this pull request in franzbischoff/anything-llm Nov 4, 2023
* include score value in similarityResponse for weaviate

* include score value in si
milarityResponse for qdrant

* include score value in si
milarityResponse for pinecone

* include score value in similarityResponse for chroma

* include score value in similarityResponse for lancedb

* distance to similarity

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
* include score value in similarityResponse for weaviate

* include score value in si
milarityResponse for qdrant

* include score value in si
milarityResponse for pinecone

* include score value in similarityResponse for chroma

* include score value in similarityResponse for lancedb

* distance to similarity

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return Relevancy Score with similarityResponse

3 participants