weaviate/weaviate · info
marshal body
Error message
marshal body
What it means
The text2vec-ollama client serializes the embeddings request ({model, input}) with json.Marshal before POSTing to <endpoint>/api/embed and wraps any failure as "marshal body". marshaling a struct of a string and []string cannot realistically fail (only channels/funcs/cycles fail), so this error almost never occurs; if you do see it, it points to modified request structs or a corrupted build rather than anything about your Ollama setup. Note the variable shadowing: the marshaled JSON is also called "body", but this error is not about the HTTP response body.
Solutions
- Read the underlying error after "marshal body: " — json.Marshal errors name the offending field type.
- Confirm you run unmodified text2vec-ollama client code; the stock embeddingsRequest (Model string, Input []string) cannot fail to marshal.
- If you extended embeddingsRequest, remove or make marshalable the unmarshalable field (e.g. marshal a separate DTO).
- If the real problem is connecting to Ollama, check OLLAMA_HOST/endpoint config — that failure surfaces as "send POST request", not "marshal body".
Example fix
// before: unmarshalable field added to request
type embeddingsRequest struct {
Model string `json:"model"`
Input []string `json:"input"`
OnDone func() `json:"-"` // chan/func fields break json.Marshal
}
// after: keep the wire DTO plain
type embeddingsRequest struct {
Model string `json:"model"`
Input []string `json:"input"`
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go: validate inputs before vectorizing with text2vec-ollama
func validOllamaVectorizeInput(input []string, model, endpoint string) error {
if len(input) == 0 { return errors.New("input must not be empty") }
if model == "" { return errors.New("moduleConfig requires a model, e.g. 'nomic-embed-text'") }
if endpoint == "" { return errors.New("ollama endpoint (e.g. http://ollama:11434) is required") }
return nil
} Try / catch
// Go: classify batch errors at the call site
vecs, errs := vectorizer.VectorizeBatch(ctx, objs, skip, cfg)
for i, err := range errs {
var orig error
if errors.As(err, &orig) && strings.Contains(err.Error(), "marshal body") {
log.Errorf("object %d: request serialization bug (report/fork issue): %v", i, err)
} else {
log.Errorf("object %d: vectorization failed: %v", i, err) // retryable transport/API errors
}
} Prevention
- Keep the request struct free of chan/func/map-with-cycle fields if you fork the client.
- Validate moduleConfig (model, apiEndpoint) before creating/patching a class so failures happen at schema time.
- Distinguish "marshal body" (serialization bug) from "send POST request" (Ollama unreachable) when reading logs.
- Use error unwrapping (errors.As/Is) instead of string-matching the outer wrapper message.
When it happens
Trigger: Calling Vectorize (object indexing) or VectorizeQuery (nearText/nearVector search) against the Ollama module and json.Marshal of embeddingsRequest returns an error — only possible if the request struct gains unmarshalable fields (chan/func/cyclic) in a modified build.
Common situations: Essentially only in custom forks of modules/text2vec-ollama/clients/ollama.go; users who see errors at this call site are usually actually hitting the later "send POST request" (Ollama unreachable) or "connection to Ollama API failed" errors.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- marshal body
- could not marshal get aliases response
- could not marshal resolve alias response
- failed to marshal usage data
- marshal body
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/f4e4f08d0d664f5d.
Report an issue: GitHub.
Appendix: source
Thrown at modules/text2vec-ollama/clients/ollama.go:71
return res, nil, 0, err
}
func (v *ollama) VectorizeQuery(ctx context.Context, input []string,
cfg moduletools.ClassConfig,
) (*modulecomponents.VectorizationResult[[]float32], error) {
return v.vectorize(ctx, input, cfg)
}
func (v *ollama) vectorize(ctx context.Context, input []string,
cfg moduletools.ClassConfig,
) (*modulecomponents.VectorizationResult[[]float32], error) {
settings := ent.NewClassSettings(cfg)
body, err := json.Marshal(embeddingsRequest{
Model: settings.Model(),
Input: input,
})
if err != nil {
return nil, errors.Wrapf(err, "marshal body")
}
endpointURL := v.urlBuilderFn(settings.ApiEndpoint())
req, err := http.NewRequestWithContext(ctx, "POST", endpointURL,
bytes.NewReader(body))
if err != nil {
return nil, errors.Wrap(err, "create POST request")
}
res, err := v.httpClient.Do(req)
if err != nil {
return nil, errors.Wrap(err, "send POST request")
}
defer res.Body.Close()
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {View on GitHub (pinned to 75aa4b6d11)