Implementation:Ollama Ollama ToEmbeddingList
Appearance
| Knowledge Sources | |
|---|---|
| Domains | API_Design, NLP |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete tool for translating Ollama embedding responses and model lists to OpenAI format provided by the openai and middleware packages.
Description
ToEmbeddingList converts an Ollama api.EmbedResponse into an OpenAI EmbeddingList with support for both float and base64 encoding formats.
EmbeddingsMiddleware handles the full request/response cycle for the /v1/embeddings endpoint.
ListMiddleware and ToListCompletion handle the /v1/models endpoint, translating Ollama's model list into OpenAI's model list format.
Usage
Invoked automatically by middleware when requests arrive at /v1/embeddings or /v1/models.
Code Reference
Source Location
- Repository: ollama
- File: openai/openai.go (ToEmbeddingList, ToListCompletion), middleware/openai.go (EmbeddingsMiddleware, ListMiddleware)
- Lines: openai.go:L398-430 (ToEmbeddingList), openai.go:L379-397 (ToListCompletion), openai.go:L345-395 (EmbeddingsMiddleware), openai.go:L277-288 (ListMiddleware)
Signature
func ToEmbeddingList(model string, r api.EmbedResponse, encodingFormat string) EmbeddingList
func ToListCompletion(r api.ListResponse) ListCompletion
func EmbeddingsMiddleware() gin.HandlerFunc
func ListMiddleware() gin.HandlerFunc
Import
import "github.com/ollama/ollama/openai"
import "github.com/ollama/ollama/middleware"
I/O Contract
Inputs (ToEmbeddingList)
| Name | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name |
| r | api.EmbedResponse | Yes | Ollama embedding response with float vectors |
| encodingFormat | string | Yes | "float" or "base64" |
Outputs (ToEmbeddingList)
| Name | Type | Description |
|---|---|---|
| EmbeddingList | EmbeddingList | OpenAI format with object, data (embeddings), model, usage |
Usage Examples
Get Embeddings
curl http://localhost:11434/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"model": "nomic-embed-text",
"input": "The food was delicious."
}'
List Models
curl http://localhost:11434/v1/models
# Returns: {"object":"list","data":[{"id":"llama3:latest","object":"model",...}]}
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment