VectorValue class
A vector of doubles stored in a document field, for example an embedding for vector search.
Create one with VectorValue(values) or VectorValue(values) and
store it as a field value; a snapshot returns it for a vector field, also
through DocumentSnapshot.getVectorValue. Find the documents with the
nearest vectors with Query.findNearest.
await firestore.doc('items/a').set(<String, Object?>{
'embedding': VectorValue(<double>[0.1, 0.2, 0.3]),
});
final DocumentSnapshot<Map<String, Object?>> snapshot =
await firestore.doc('items/a').get();
final List<double>? values = (snapshot.get('embedding') as VectorValue?)
?.toArray();
On a real database, vector search needs a vector index on the field, which you create with the Google Cloud tools, not with this SDK.
A vector is not a list: it is a value of its own type and is not equal to
a List<double> with the same numbers. In orderBy, vectors sort after
arrays and before maps, by their length first and then by their values.
Constructors
-
VectorValue(List<
double> values) -
Creates a vector holding a copy of
values; later changes tovaluesdo not affect the vector. -
VectorValue.fromJson(Map<
String, Object?> json) -
Builds a vector from a JSON map created by toJson.
factory
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toArray(
) → List< double> - Returns a copy of the vector as a list of doubles; changing the list does not change the vector.
-
toJson(
) → Map< String, Object> -
A JSON-serializable representation of this vector, in the same shape as the JS SDK's
VectorValue.toJSON(): itstype(jsonType) andvectorValues. Read it back with VectorValue.fromJson. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override