ฟังก์ชันเวกเตอร์
| ชื่อ | คำอธิบาย |
COSINE_DISTANCE
|
แสดงผลระยะทางโคไซน์ระหว่างเวกเตอร์ 2 เวกเตอร์ |
DOT_PRODUCT
|
แสดงผลดอทโปรดักต์ระหว่าง 2 เวกเตอร์ |
EUCLIDEAN_DISTANCE
|
แสดงผลระยะทางแบบยุคลิดระหว่างเวกเตอร์ 2 ตัว |
MANHATTAN_DISTANCE
|
แสดงผลระยะทางแมนฮัตตันระหว่างเวกเตอร์ 2 เวกเตอร์ |
VECTOR_LENGTH
|
แสดงผลจำนวนองค์ประกอบในเวกเตอร์ |
COSINE_DISTANCE
ไวยากรณ์:
cosine_distance(x: VECTOR, y: VECTOR) -> FLOAT64
คำอธิบาย:
แสดงผลระยะทางโคไซน์ระหว่าง x กับ y
Web
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await execute(db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).as("cosineDistance")));
Swift
let sampleVector = [0.0, 1, 2, 3, 4, 5] let result = try await db.pipeline() .collection("books") .select([ Field("embedding").cosineDistance(sampleVector).as("cosineDistance") ]) .execute()
Kotlin
val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0) val result = db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).alias("cosineDistance") ) .execute()
Java
double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").cosineDistance(sampleVector).alias("cosineDistance") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field from google.cloud.firestore_v1.vector import Vector sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) result = ( client.pipeline() .collection("books") .select( Field.of("embedding").cosine_distance(sample_vector).as_("cosineDistance") ) .execute() )
DOT_PRODUCT
ไวยากรณ์:
dot_product(x: VECTOR, y: VECTOR) -> FLOAT64
คำอธิบาย:
แสดงผลดอทโปรดักต์ของ x และ y
Web
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await execute(db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).as("dotProduct") ) );
Swift
let sampleVector = [0.0, 1, 2, 3, 4, 5] let result = try await db.pipeline() .collection("books") .select([ Field("embedding").dotProduct(sampleVector).as("dotProduct") ]) .execute()
Kotlin
val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0) val result = db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).alias("dotProduct") ) .execute()
Java
double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").dotProduct(sampleVector).alias("dotProduct") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field from google.cloud.firestore_v1.vector import Vector sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) result = ( client.pipeline() .collection("books") .select(Field.of("embedding").dot_product(sample_vector).as_("dotProduct")) .execute() )
EUCLIDEAN_DISTANCE
ไวยากรณ์:
euclidean_distance(x: VECTOR, y: VECTOR) -> FLOAT64
คำอธิบาย:
คำนวณระยะทางแบบยุคลิดระหว่าง x กับ y
Web
const sampleVector = [0.0, 1, 2, 3, 4, 5]; const result = await execute(db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).as("euclideanDistance") ) );
Swift
let sampleVector = [0.0, 1, 2, 3, 4, 5] let result = try await db.pipeline() .collection("books") .select([ Field("embedding").euclideanDistance(sampleVector).as("euclideanDistance") ]) .execute()
Kotlin
val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0) val result = db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).alias("euclideanDistance") ) .execute()
Java
double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").euclideanDistance(sampleVector).alias("euclideanDistance") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field from google.cloud.firestore_v1.vector import Vector sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) result = ( client.pipeline() .collection("books") .select( Field.of("embedding") .euclidean_distance(sample_vector) .as_("euclideanDistance") ) .execute() )
MANHATTAN_DISTANCE
ไวยากรณ์:
manhattan_distance(x: VECTOR, y: VECTOR) -> FLOAT64
คำอธิบาย:
คำนวณระยะทางแมนฮัตตันระหว่าง x กับ y
VECTOR_LENGTH
ไวยากรณ์:
vector_length(vector: VECTOR) -> INT64
คำอธิบาย:
แสดงผลจำนวนองค์ประกอบใน VECTOR
Web
const result = await execute(db.pipeline() .collection("books") .select( field("embedding").vectorLength().as("vectorLength") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("embedding").vectorLength().as("vectorLength") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("embedding").vectorLength().alias("vectorLength") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("embedding").vectorLength().alias("vectorLength") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("embedding").vector_length().as_("vectorLength")) .execute() )