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

support ollama api/embed #2614

Open
qinst64 opened this issue Aug 1, 2024 · 1 comment
Open

support ollama api/embed #2614

qinst64 opened this issue Aug 1, 2024 · 1 comment
Labels
EF Embedding Functions enhancement New feature or request

Comments

@qinst64
Copy link

qinst64 commented Aug 1, 2024

Describe the problem

In Ollama doc there are both api/embeddings and api/embed
and saying

Note: api/embedding has been superseded by /api/embed

will OllamaEmbeddingFunction support api/embed?

btw, they have different behaviors, how do I migrate?

import requests

r = requests.post("http://localhost:11434/api/embeddings",
    json={"model": "nomic-embed-text", "prompt": "hello"},
).json()
print(r.keys()) # dict_keys(['embedding'])
print(r['embedding'][:5]) #[0.4556913375854492, -0.2971344590187073, -4.071754455566406, -0.18389371037483215, 0.711044192314148]

r = requests.post("http://localhost:11434/api/embed",
    json={"model": "nomic-embed-text", "input": "hello"},
).json()
print(r.keys()) # dict_keys(['model', 'embeddings']
print(r['embeddings'][0][:5]) # [0.019435372, -0.012672874, -0.17366156, -0.007843122, 0.03032625]

The input (prompt vs input) and output (embedding vs embeddings, 1D list vs 2D list) are easy to deal with.
But why output vectors are differenct?

Describe the proposed solution

support api/embed.
give instruction for switching from api/embeddings to api/embed smoothly.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

@qinst64 qinst64 added the enhancement New feature or request label Aug 1, 2024
@tazarov
Copy link
Contributor

tazarov commented Aug 2, 2024

@qinst64, let's do some brainstorming here. In general, things in AI move very fast and frequently break. I think that the Ollama team has done a good job of "slow" deprecation of the endpoint.

I think we can move forward with just support /api/embed (as default), dropping the legacy request payload type (the one containing prompt).

But maybe a smarter approach would be to simply ask the user to supply Ollama base API (e.g. the one without /api/xxx) and then go from there. We can check if the version is above 0.3.0 (/api/version) and then use the new endpoint otherwise use the old one. This approach has the drawback that if things are behind a custom endpoint (exposed via proxy) then this is a little less flexible. Perhaps mitigated by also adding an embedding_endpoint parameter with a default /api/embed.

@tazarov tazarov added the EF Embedding Functions label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EF Embedding Functions enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants