fix(s3vectors): handle vector=None in update() to prevent boto3 validation error (#4594)
This commit is contained in:
@@ -122,7 +122,37 @@ class S3Vectors(VectorStoreBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def update(self, vector_id, vector=None, payload=None):
|
def update(self, vector_id, vector=None, payload=None):
|
||||||
# S3 Vectors uses put_vectors for updates (overwrite)
|
# S3 Vectors uses put_vectors for updates (overwrite).
|
||||||
|
# When vector=None (e.g. metadata-only update triggered by event=NONE),
|
||||||
|
# fetch the existing vector data first to avoid passing None to boto3
|
||||||
|
# which causes a parameter validation error:
|
||||||
|
# "Invalid type for parameter vectors[0].data.float32, value: None"
|
||||||
|
if vector is None:
|
||||||
|
existing = self.get(vector_id)
|
||||||
|
if existing is None:
|
||||||
|
logger.warning(f"update called with vector=None but {vector_id} not found; skipping")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
response = self.client.get_vectors(
|
||||||
|
vectorBucketName=self.vector_bucket_name,
|
||||||
|
indexName=self.collection_name,
|
||||||
|
keys=[vector_id],
|
||||||
|
returnData=True,
|
||||||
|
returnMetadata=True,
|
||||||
|
)
|
||||||
|
vectors = response.get("vectors", [])
|
||||||
|
if not vectors:
|
||||||
|
logger.warning(f"update: no vector data found for {vector_id}; skipping")
|
||||||
|
return
|
||||||
|
vector = vectors[0].get("data", {}).get("float32")
|
||||||
|
if vector is None:
|
||||||
|
logger.warning(f"update: float32 data is None for {vector_id}; skipping")
|
||||||
|
return
|
||||||
|
if payload is None:
|
||||||
|
payload = existing.payload
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"update: failed to fetch existing vector for {vector_id}: {e}")
|
||||||
|
return
|
||||||
self.insert(vectors=[vector], payloads=[payload], ids=[vector_id])
|
self.insert(vectors=[vector], payloads=[payload], ids=[vector_id])
|
||||||
|
|
||||||
def get(self, vector_id) -> Optional[OutputData]:
|
def get(self, vector_id) -> Optional[OutputData]:
|
||||||
|
|||||||
Reference in New Issue
Block a user