Skip to content
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

[bug] Nearest neighbor search errors if using non-default feature size for a text embedding model #49

Closed
hydrosquall opened this issue Jul 13, 2024 · 2 comments · Fixed by #50

Comments

@hydrosquall
Copy link
Contributor

hydrosquall commented Jul 13, 2024

Bug reproduction steps

  1. Generate a scope in latentscope 0.3.0 using open-ai-text-embedding-3-small model, but don't use the default feature size of 1536, change it to something smaller 768.
  2. Visit the /datasets/<DATASET_NAME>/explore/<SCOPE_NAME> route , and use the "nearest neighbor search" feature
  3. Submitting terms in the search box has no effect. Upon checking server logs, you'll have a message like this

image

Bug explanation

I think the error message demonstrates why the button has no effect . The search term was embedded with the default model size of 1536 instead of with the size of the embeddings it'll be matched against

embedding = model.embed([query], dimensions=dimensions)

For nearest neighbors search to work, the query term's vector has to match the size of the embeddings for this scope

Possible fixes

  1. Have the frontend pass updated dimensions through to the dimensions GET parameter, vs
  2. The frontend shouldn't worry about this, the dimensions should be set based on the size of the features in the loaded model . In that case dimensions could be completely removed from the server's URL params since as far as I can see, the frontend does not send dimensions as a query parameter.

fetch(`${apiUrl}/search/nn?dataset=${datasetId}&query=${query}&embedding_id=${searchModel}`)

@enjalot
Copy link
Owner

enjalot commented Jul 13, 2024

thanks for the detailed bug report, this does make sense and should be accounted for.

We track the dimensions for the embedding in the scope.json ( along with all the other metadata from the process) so I think it would be fine for the front end to call the nearest neighbor endpoint with the dims. The API needs to be updated to then pass the dimensions to the model. The providers that support matroyshka take it as a parameter to embed.

@hydrosquall
Copy link
Contributor Author

hydrosquall commented Jul 13, 2024

Sounds good, I think the fix is straightforward 👍 . The API appears to already have a setting to read the dimensions if the frontend provides them.

#50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants