Skip to content

[ENH] When embedding functions have defined default_space, use them if the user hasn't specified #4321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jairad26
Copy link
Contributor

@jairad26 jairad26 commented Apr 18, 2025

Description of changes

This PR uses the default space defined for an embedding function if available, closes #2128

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Copy link
Contributor Author

@jairad26 jairad26 marked this pull request as ready for review April 18, 2025 17:02
@jairad26 jairad26 marked this pull request as draft April 19, 2025 01:23
@jairad26 jairad26 force-pushed the jai/set-default-space-by-ef branch 2 times, most recently from a131515 to 43a52d6 Compare April 21, 2025 16:14
@jairad26 jairad26 marked this pull request as ready for review April 21, 2025 16:16
@jairad26 jairad26 force-pushed the jai/set-default-space-by-ef branch 4 times, most recently from 0b1b9ee to d3baad8 Compare April 25, 2025 17:19
@jairad26 jairad26 force-pushed the jai/set-default-space-by-ef branch from d3baad8 to 30d251e Compare April 26, 2025 00:02
@@ -377,6 +377,24 @@ def create_collection_configuration_to_json(
"config": ef.get_config(),
}
register_embedding_function(type(ef)) # type: ignore
if hnsw_config is not None and hnsw_config.get("space") is None:
try:
hnsw_config["space"] = ef.default_space()
Copy link
Collaborator

@HammadB HammadB Apr 26, 2025

Choose a reason for hiding this comment

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

is there not some base impl that will always be used? I am bit a confused by this pattern. You could also check if its the base impl.

If default_space is not specified, what is the behavior we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, the base impl is l2, which is the space we define in our docs as the default. so when available, it’ll pull from the ef’s default otherwise the base one

Copy link
Contributor Author

@jairad26 jairad26 Apr 26, 2025

Choose a reason for hiding this comment

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

and if they’re running on an old version or are using a legacy custom ef (which won't have the base impl), the try will fail and issue a warning

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.

[Feature Request]: Auto-set distance metric based on embedding function
2 participants