griptape
griptape copied to clipboard
Support Upserting Custom Vectors In Marqo Vector Store Driver
This is currently unimplemented but it is supported with custom vectors. Rough implementation:
def upsert_vector(
self,
vector: list[float],
*,
vector_id: Optional[str] = None,
namespace: Optional[str] = None,
meta: Optional[dict] = None,
**kwargs: Any,
) -> str:
"""Upsert a vector into the Marqo index.
Args:
vector: The vector to be indexed.
vector_id: The ID for the vector. If None, Marqo will generate an ID.
namespace: An optional namespace for the vector.
meta: An optional dictionary of metadata for the vector.
kwargs: Additional keyword arguments to pass to the Marqo client.
Raises:
Exception: This function is not yet implemented.
Returns:
The ID of the vector that was added.
"""
doc = {
"_id": vector_id,
"vector": {"vector": vector},
"namespace": namespace,
"meta": meta,
}
response = self.client.index(self.index).add_documents(
[doc], mappings={"vector": {"type": "custom_vector"}}, tensor_fields=["vector"]
)
if isinstance(response, dict) and "items" in response and response["items"]:
return response["items"][0]["_id"]
else:
raise ValueError(f"Failed to upsert text: {response}")