@@ -14,7 +14,7 @@ import (
1414const defaultBaseURLOllama = "http://localhost:11434/api"
1515
1616type ollamaResponse struct {
17- Embedding []float32 `json:"embedding "`
17+ Embeddings [][] float32 `json:"embeddings "`
1818}
1919
2020// NewEmbeddingFuncOllama returns a function that creates embeddings for a text
@@ -39,16 +39,17 @@ func NewEmbeddingFuncOllama(model string, baseURLOllama string) EmbeddingFunc {
3939 return func (ctx context.Context , text string ) ([]float32 , error ) {
4040 // Prepare the request body.
4141 reqBody , err := json .Marshal (map [string ]string {
42- "model" : model ,
43- "prompt " : text ,
42+ "model" : model ,
43+ "input " : text ,
4444 })
45+
4546 if err != nil {
4647 return nil , fmt .Errorf ("couldn't marshal request body: %w" , err )
4748 }
4849
4950 // Create the request. Creating it with context is important for a timeout
5051 // to be possible, because the client is configured without a timeout.
51- req , err := http .NewRequestWithContext (ctx , "POST" , baseURLOllama + "/embeddings " , bytes .NewBuffer (reqBody ))
52+ req , err := http .NewRequestWithContext (ctx , "POST" , baseURLOllama + "/embed " , bytes .NewBuffer (reqBody ))
5253 if err != nil {
5354 return nil , fmt .Errorf ("couldn't create request: %w" , err )
5455 }
@@ -78,11 +79,11 @@ func NewEmbeddingFuncOllama(model string, baseURLOllama string) EmbeddingFunc {
7879 }
7980
8081 // Check if the response contains embeddings.
81- if len (embeddingResponse .Embedding ) == 0 {
82+ if len (embeddingResponse .Embeddings ) == 0 {
8283 return nil , errors .New ("no embeddings found in the response" )
8384 }
8485
85- v := embeddingResponse .Embedding
86+ v := embeddingResponse .Embeddings [ 0 ]
8687 checkNormalized .Do (func () {
8788 if isNormalized (v ) {
8889 checkedNormalized = true
0 commit comments