Skip to content

Commit 5fe7ba1

Browse files
authored
runner: always truncate embeddings requests (ollama#12714)
1 parent d2b63c1 commit 5fe7ba1

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

integration/embed_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ func TestAllMiniLMEmbedTruncate(t *testing.T) {
258258
}
259259
},
260260
},
261+
{
262+
name: "boundary truncation",
263+
request: api.EmbedRequest{
264+
Model: "all-minilm",
265+
Input: "why is the sky blue? Why is the sky blue? hi there my",
266+
Options: map[string]any{"num_ctx": 16},
267+
},
268+
check: func(res *api.EmbedResponse, err error) {
269+
if err != nil {
270+
t.Fatal(err)
271+
}
272+
},
273+
},
261274
}
262275

263276
for _, req := range cases {

runner/llamarunner/runner.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,14 @@ func (s *Server) embeddings(w http.ResponseWriter, r *http.Request) {
697697

698698
w.Header().Set("Content-Type", "application/json")
699699

700-
seq, err := s.NewSequence(req.Content, nil, NewSequenceParams{embedding: true})
700+
seq, err := s.NewSequence(req.Content, nil, NewSequenceParams{
701+
embedding: true,
702+
703+
// TODO (jmorganca): this should be provided by the server via the
704+
// request options and truncated here in the runner, instead of relying on
705+
// the server's truncate logic
706+
truncate: true,
707+
})
701708
if err != nil {
702709
http.Error(w, fmt.Sprintf("Failed to create new sequence: %v", err), http.StatusInternalServerError)
703710
return

runner/ollamarunner/runner.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,14 @@ func (s *Server) embeddings(w http.ResponseWriter, r *http.Request) {
946946
}
947947

948948
w.Header().Set("Content-Type", "application/json")
949-
seq, err := s.NewSequence(req.Content, nil, NewSequenceParams{embedding: true})
949+
seq, err := s.NewSequence(req.Content, nil, NewSequenceParams{
950+
embedding: true,
951+
952+
// TODO (jmorganca): this should be provided by the server via the
953+
// request options and truncated here in the runner, instead of relying on
954+
// the server's truncate logic
955+
truncate: true,
956+
})
950957
if err != nil {
951958
http.Error(w, fmt.Sprintf("failed to create new sequence: %v", err), http.StatusInternalServerError)
952959
return

0 commit comments

Comments
 (0)