[GH-ISSUE #502] Better Document /api/embeddings #25992

Closed
opened 2026-04-22 01:52:34 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @FairyTail2000 on GitHub (Sep 10, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/502

It's currently not very clear on how to use is and how it's relation is to the EMBED Modelfile instruction.

Can you enlighten me and/or update the wiki and examples?

Originally created by @FairyTail2000 on GitHub (Sep 10, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/502 It's currently not very clear on how to use is and how it's relation is to the EMBED Modelfile instruction. Can you enlighten me and/or update the wiki and examples?
Author
Owner

@saul-jb commented on GitHub (Sep 14, 2023):

It's currently not very clear on how to use is and how it's relation is to the EMBED Modelfile instruction.

I am only just learning about this myself but here is my findings.

The embedding is a way to convert generic content into a Vector representation (a list of numbers). This is useful because we can perform vector mathematics on these to compare them and how closely they relate together. You could compare a list of embeddings created from a long list of files to an embedding created from a prompt, then you could use the embedding the most closely matches and reverse lookup the file of relevance. This is essentially a semantic search.

The /api/embeddings will take a prompt and generate an embedding from it and return it to you. It is up to you to figure out what you want to do with it.

The EMBED Modelfile instruction appears create an embedding which allows it to use that data to when providing a result.

<!-- gh-comment-id:1718810645 --> @saul-jb commented on GitHub (Sep 14, 2023): > It's currently not very clear on how to use is and how it's relation is to the EMBED Modelfile instruction. I am only just learning about this myself but here is my findings. The embedding is a way to convert generic content into a Vector representation (a list of numbers). This is useful because we can perform vector mathematics on these to compare them and how closely they relate together. You could compare a list of embeddings created from a long list of files to an embedding created from a prompt, then you could use the embedding the most closely matches and reverse lookup the file of relevance. This is essentially a semantic search. The /api/embeddings will take a prompt and generate an embedding from it and return it to you. It is up to you to figure out what you want to do with it. The EMBED Modelfile instruction appears create an embedding which allows it to use that data to when providing a result.
Author
Owner

@FairyTail2000 commented on GitHub (Sep 14, 2023):

Thanks for your explanation. It makes sense now. Maybe @jmorganca can cover this in the documentation

<!-- gh-comment-id:1719032847 --> @FairyTail2000 commented on GitHub (Sep 14, 2023): Thanks for your explanation. It makes sense now. Maybe @jmorganca can cover this in the documentation
Author
Owner

@fmnxl commented on GitHub (Sep 26, 2023):

So the embeddings won't be searched automatically when running inference with the model?

<!-- gh-comment-id:1735197739 --> @fmnxl commented on GitHub (Sep 26, 2023): So the embeddings won't be searched automatically when running inference with the model?
Author
Owner

@BruceMacD commented on GitHub (Sep 26, 2023):

It's not well documented since there is still a lot of work to do around embeddings, but you can automatically add the top 3 closest embeddings to a prompt using the {{ .Embed }} variable in your prompt template.

Here is an example Modelfile:

FROM llama2
EMBED <file path>.txt
TEMPLATE """
[INST] <<SYS>>You are a librarian that can answer questions about historical events with detail and accuracy.<</SYS>>

{{- if .Embed }}If this information is relevant use it to answer the prompt, otherwise ignore it: {{ .Embed }}
Prompt: {{- end }}{{ .Prompt }} [/INST] 
<!-- gh-comment-id:1735635352 --> @BruceMacD commented on GitHub (Sep 26, 2023): It's not well documented since there is still a lot of work to do around embeddings, but you can automatically add the top 3 closest embeddings to a prompt using the `{{ .Embed }}` variable in your prompt template. Here is an example Modelfile: ``` FROM llama2 EMBED <file path>.txt TEMPLATE """ [INST] <<SYS>>You are a librarian that can answer questions about historical events with detail and accuracy.<</SYS>> {{- if .Embed }}If this information is relevant use it to answer the prompt, otherwise ignore it: {{ .Embed }} Prompt: {{- end }}{{ .Prompt }} [/INST] ```
Author
Owner

@jmorganca commented on GitHub (Oct 26, 2023):

Hi @FairyTail2000, for documentation on /api/embeddings, check out https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-embeddings

In terms of using these embeddings, check out this guide by @simonw which is a great guide on what embeddings are and how to use them.

<!-- gh-comment-id:1780224430 --> @jmorganca commented on GitHub (Oct 26, 2023): Hi @FairyTail2000, for documentation on `/api/embeddings`, check out https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-embeddings In terms of using these embeddings, check out [this guide](https://simonwillison.net/2023/Oct/23/embeddings) by @simonw which is a great guide on what embeddings are and how to use them.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#25992