Overview
TheDoc class represents a document in Zvec with its metadata, vectors, and scalar fields. It is used both for inserting new documents and representing search results.
Class Definition
Attributes
Unique identifier for the document. Must be unique within a collection.
Relevance score from search queries. Automatically populated by query operations. Higher scores indicate better matches.
Named vector embeddings associated with the document. Keys must match vector field names defined in the collection schema.Values can be:
- Python lists:
[0.1, 0.2, 0.3] - NumPy arrays:
np.array([0.1, 0.2, 0.3])(automatically converted to lists)
Scalar metadata fields (e.g., title, category, timestamp). Keys must match field names in the collection schema.Supported value types depend on the field schema (strings, numbers, booleans, arrays).
Methods
vector()
Get a specific vector by name.Name of the vector field to retrieve.
None if not found.
field()
Get a specific scalar field by name.Name of the field to retrieve.
None if not found.
Usage Examples
Creating Documents for Insertion
Working with Search Results
Multi-Vector Documents
Important Notes
Immutability: Doc objects are immutable. All attributes are set during initialization and cannot be modified afterward.
Automatic Conversion: NumPy arrays in the
vectors dict are automatically converted to Python lists for JSON serialization and immutability.See Also
- Collection.insert() - Insert documents into a collection
- Collection.query() - Query documents by similarity
- CollectionSchema - Define document structure
- VectorSchema - Define vector fields