$vector in collections (Python)

$vector is a reserved field in documents. It stores a vector embedding that is used for vector search and for the vector search component of hybrid search.

Only vector-enabled collections support the $vector field. For more information, see Create a collection that can store vector embeddings.

Insert and update a document’s $vector field

When you insert or update a document, you can use the $vector field to store a vector embedding for the document. For an example, see Insert documents with vector embeddings.

All vector embeddings in a collection should be generated by the same model with the same dimensions. Using mismatched embeddings produces unreliable and incorrect results in vector searches. The Data API only checks that the dimensions are the same; it doesn’t check whether the embeddings are from different models.

If your collection has an embedding provider integration, you can use the $vectorize field to automatically generate a vector embedding from a string. The Data API stores the generated vector embedding in the document’s $vector field. However, you can’t include both the $vector and $vectorize fields in the same insert or update operation.

When you find, update, replace, or delete documents, you can use the $vector field to perform a vector search. For an example, see Use vector search to find documents.

Similarly, when you find and rerank documents, you can use the $vector field to perform a hybrid search. For an example, see Find documents with a hybrid search.

Return the $vector field

By default, the Data API excludes the $vector field from returned documents. If you want the Data API to return the $vector field, you must use a projection to explicitly include the $vector field in the response.

Binary encoding of vector embeddings

When inserting or updating documents, you can specify the $vector field as an array of floats or use the astrapy.data_types.DataAPIVector class to represent and encode the vector embedding. Similarly, for vector searches, you can provide the search vector as an array of floats or use the astrapy.data_types.DataAPIVector class. DataAPIVector is a wrapper around a list of floats.

from astrapy.data_types import DataAPIVector

vector = DataAPIVector([.08, .68, .30])

For collections and documents, regardless of whether you use a DataAPIVector object or a list of floats, vector embeddings are binary-encoded by default, which improves performance. To change the default encoding, see Serdes Options and Custom Data Types.

When you read the value of a $vector field, the client always returns a DataAPIVector object, unless you change the default ser/des behavior.

For more information, see DataAPIVector.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM