Skip to content

Conversation

@juanfe88
Copy link

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕
I was not the one submitting the issue however I ran into the same problem and figured out I could try and fix it
#87

@juanfe88 juanfe88 requested review from a team as code owners April 29, 2025 14:37
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/langchain-google-firestore-python API. label Apr 29, 2025
query: List[float],
k: int = DEFAULT_TOP_K,
filters: Optional[BaseFilter] = None,
with_scores: Optional[bool] = False,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the support!

Could we pass distance_result_field as parameter so that we could calculate the score based on any field (not limit to distance)?

Copy link
Author

@juanfe88 juanfe88 May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it as optional with a default value, but it can be overriden. I also added a test for these cases WDYT ? 😄

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! In this case, do we still need with_scores? Since distance_result_field is optional, with_scores field can be implicitly done by distance_result_field.

(ex: if distance_result_field is specified, return scores)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I just refactored it so that we can get the scores just by passing the name of field

This change introduces the `distance_result_field` parameter to `similarity_search_with_score` in `FirestoreVectorStore`.

Users can now specify a custom field name for the distance score returned in the results, defaulting to "distance". This provides flexibility and helps avoid potential field name conflicts when results are processed.

The internal `_similarity_search` method was updated to accept and use this custom field name. A new test case verifies this functionality.
@juanfe88 juanfe88 changed the title add similarity search with distance score feat: add similarity search with distance score May 12, 2025
pl04351820
pl04351820 previously approved these changes May 12, 2025
query: List[float],
k: int = DEFAULT_TOP_K,
filters: Optional[BaseFilter] = None,
with_scores: Optional[bool] = False,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! In this case, do we still need with_scores? Since distance_result_field is optional, with_scores field can be implicitly done by distance_result_field.

(ex: if distance_result_field is specified, return scores)

juanfe88 added 2 commits May 12, 2025 22:26
Remove the `with_scores` parameter from the `_similarity_search`
method. The `distance_result_field` parameter now solely determines
if distance scores should be calculated and returned by the underlying
`find_nearest` call.

This change simplifies the method's API and internal logic by making
the provision of `distance_result_field` the explicit way to request
scores. The `similarity_search_with_score` method has been updated
accordingly.
@juanfe88
Copy link
Author

Hi @pcostell ! 👋 Hope you're well.

I’m circling back to this PR after a while. I've verified that the changes are still working correctly. Please let me know if you need any other updates from me to get this merged.

I also have some Async support features I'd love to contribute, but since the repo has been a little inactive recently, I wanted to make sure you are still reviewing new contributions before I open a new PR.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the googleapis/langchain-google-firestore-python API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants