You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Pydantic validation error with list-type metadata in vector search (#3797) (#4173)
# Fix for Issue #3797
## Problem
Vector store search failed with Pydantic ValidationError when chunk
metadata contained list-type values.
**Error:**
```
ValidationError: 3 validation errors for VectorStoreSearchResponse
attributes.tags.str: Input should be a valid string
attributes.tags.float: Input should be a valid number
attributes.tags.bool: Input should be a valid boolean
```
**Root Cause:**
- `Chunk.metadata` accepts `dict[str, Any]` (any type allowed)
- `VectorStoreSearchResponse.attributes` requires `dict[str, str | float
| bool]` (primitives only)
- Direct assignment at line 641 caused validation failure for
non-primitive types
## Solution
Added utility function to filter metadata to primitive types before
creating search response.
## Impact
**Fixed:**
- Vector search works with list metadata (e.g., `tags: ["transformers",
"gpu"]`)
- Lists become searchable as comma-separated strings
- No ValidationError on search responses
**Preserved:**
- Full metadata still available in `VectorStoreContent.metadata`
- No API schema changes
- Backward compatible with existing primitive metadata
**Affected:**
All vector store providers using `OpenAIVectorStoreMixin`: FAISS,
Chroma, Qdrant, Milvus, Weaviate, PGVector, SQLite-vec
## Testing
tests/unit/providers/vector_io/test_vector_utils.py::test_sanitize_metadata_for_attributes
---------
Co-authored-by: Ashwin Bharambe <[email protected]>
Co-authored-by: Francisco Arceo <[email protected]>
Copy file name to clipboardExpand all lines: client-sdks/stainless/openapi.yml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9862,9 +9862,21 @@ components:
9862
9862
title: Object
9863
9863
default: vector_store.file
9864
9864
attributes:
9865
-
additionalProperties: true
9865
+
additionalProperties:
9866
+
anyOf:
9867
+
- type: string
9868
+
maxLength: 512
9869
+
- type: number
9870
+
- type: boolean
9871
+
title: string | number | boolean
9872
+
propertyNames:
9873
+
type: string
9874
+
maxLength: 64
9866
9875
type: object
9876
+
maxProperties: 16
9867
9877
title: Attributes
9878
+
description: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
Copy file name to clipboardExpand all lines: docs/static/deprecated-llama-stack-spec.yaml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6705,9 +6705,21 @@ components:
6705
6705
title: Object
6706
6706
default: vector_store.file
6707
6707
attributes:
6708
-
additionalProperties: true
6708
+
additionalProperties:
6709
+
anyOf:
6710
+
- type: string
6711
+
maxLength: 512
6712
+
- type: number
6713
+
- type: boolean
6714
+
title: string | number | boolean
6715
+
propertyNames:
6716
+
type: string
6717
+
maxLength: 64
6709
6718
type: object
6719
+
maxProperties: 16
6710
6720
title: Attributes
6721
+
description: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
Copy file name to clipboardExpand all lines: docs/static/experimental-llama-stack-spec.yaml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6061,9 +6061,21 @@ components:
6061
6061
title: Object
6062
6062
default: vector_store.file
6063
6063
attributes:
6064
-
additionalProperties: true
6064
+
additionalProperties:
6065
+
anyOf:
6066
+
- type: string
6067
+
maxLength: 512
6068
+
- type: number
6069
+
- type: boolean
6070
+
title: string | number | boolean
6071
+
propertyNames:
6072
+
type: string
6073
+
maxLength: 64
6065
6074
type: object
6075
+
maxProperties: 16
6066
6076
title: Attributes
6077
+
description: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
Copy file name to clipboardExpand all lines: docs/static/llama-stack-spec.yaml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -8883,9 +8883,21 @@ components:
8883
8883
title: Object
8884
8884
default: vector_store.file
8885
8885
attributes:
8886
-
additionalProperties: true
8886
+
additionalProperties:
8887
+
anyOf:
8888
+
- type: string
8889
+
maxLength: 512
8890
+
- type: number
8891
+
- type: boolean
8892
+
title: string | number | boolean
8893
+
propertyNames:
8894
+
type: string
8895
+
maxLength: 64
8887
8896
type: object
8897
+
maxProperties: 16
8888
8898
title: Attributes
8899
+
description: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
Copy file name to clipboardExpand all lines: docs/static/stainless-llama-stack-spec.yaml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9862,9 +9862,21 @@ components:
9862
9862
title: Object
9863
9863
default: vector_store.file
9864
9864
attributes:
9865
-
additionalProperties: true
9865
+
additionalProperties:
9866
+
anyOf:
9867
+
- type: string
9868
+
maxLength: 512
9869
+
- type: number
9870
+
- type: boolean
9871
+
title: string | number | boolean
9872
+
propertyNames:
9873
+
type: string
9874
+
maxLength: 64
9866
9875
type: object
9876
+
maxProperties: 16
9867
9877
title: Attributes
9878
+
description: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
0 commit comments