support ollama api/embed
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, 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.
i believe this has been solved, closing