Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Vector Functions and Operators

Updated on 2024-06-03 GMT+08:00

floatvector supports data conversion between the vector type and array type. In addition, strings in specific formats can be converted to the vector type.

array<->floatvector: During data type conversion, the vector data type can be freely converted to the corresponding array type. The member data type of the floatvector vector is floating point.

string ->floatvector: You need to pay attention to the character string format. You need to contain arrays using square brackets ([]) or braces ({}) and separate elements using commas (,).

floatvector

Function: Converts array data into vector data.

Scenario 1:

Input parameter type: anyarray

Output parameter type: floatvector

Code example:

gaussdb=# SELECT floatvector(ARRAY[1,2,9.3]);

Scenario 2:

Type of input parameter 1: floatvector

Type of input parameter 2: integer

Output parameter type: floatvector

Code example:

gaussdb=# SELECT floatvector(floatvector('[1,2,9.3]'),3);

vector_to_array

Function: Converts vector data into array data.

Input parameter type: floatvector

Output parameter type: real[]

Code example:

gaussdb=# SELECT vector_to_array(floatvector('[1,2,3]'));

text_to_vector

Function: Converts character data into vector data.

Input parameter type: cstring

Output parameter type: floatvector

Code example:

gaussdb=# SELECT text_to_vector('[1,2,9.3]');

vector_in

Function: Specifies the floatvector input conversion function (text format).

Type of input parameter 1: cstring

Type of input parameter 2: OID

Type of input parameter 3: int4

Output parameter type: floatvector

Code example:

gaussdb=# SELECT vector_in('[1,2,3]',701,3);

vector_out

Function: Specifies the floatvector output conversion function (text format).

Input parameter type: floatvector

Output parameter type: cstring

Code example:

gaussdb=# SELECT vector_out(floatvector('[1,2,3]'));

vector_send

Function: Specifies the floatvector input conversion function (binary format).

Input parameter type: floatvector

Output parameter type: bytea

Code example:

gaussdb=# SELECT vector_send(floatvector('[1,2,3]'));

vector_recv

Function: Specifies the floatvector output conversion function (binary format).

Type of input parameter 1: integer

Type of input parameter 2: OID

Type of input parameter 3: int4

Output parameter type: floatvector

Code example:

-- This is a system function and cannot be called by SQL statements.

vector_typmod_in

Function: Specifies the floatvector input type modifier function.

Input parameter type: cstring[]

Output parameter type: integer

Code example:

gaussdb=# SELECT vector_typmod_in( '{1}' );
NOTE:
  • Vector data type members support only single precision.
  • Only the same dimension is supported for vector calculation. If the dimensions are different, an error is reported.
  • floatvector supports vector addition and subtraction. The dot product operation is performed by the inner_product function.
  • When creating a table, you must specify dimensions for each vector type. If the dimensions of the inserted data are different from the specified dimensions, the database reports an error.
  • If data has been inserted into the data table, the data in the table must comply with the dimension settings when the vector dimensions are changed. Otherwise, the database reports an error. If a vector index has been created for a vector attribute, the data type of the attribute cannot be switched to another data type, and the database reports an error.

boolvector

Scenario 1:

Function: Converts array data into vector data.

Input parameter type: anyarray

Output parameter type: boolvector

Code example:

gaussdb=# SELECT boolvector(ARRAY[1,0,1]);

Scenario 2:

Function: Converts to boolvector and detects dimensions.

Type of input parameter 1: boolvector

Type of input parameter 2: integer

Output parameter type: boolvector

Code example:

gaussdb=# SELECT boolvector(boolvector('[1,0,1]'),3);

boolvector_to_array

Function: Converts vector data into array data.

Input parameter type: boolvector

Output parameter type: anyarray

Code example:

gaussdb=# SELECT boolvector_to_array(boolvector('[1,0,1]'));

text_to_boolvector

Function: Converts character data into vector data.

Input parameter type: cstring

Output parameter type: boolvector

Code example:

gaussdb=# SELECT text_to_boolvector('[1,1,1]');

bool_vector_in

Function: Specifies the boolvector input conversion function (text format).

Type of input parameter 1: cstring

Type of input parameter 2: OID

Type of input parameter 3: int4

Output parameter type: boolvector

Code example:

gaussdb=# SELECT bool_vector_in('[1,1,1]',701,3);

bool_vector_out

Function: Specifies the boolvector output conversion function (text format).

Input parameter type: boolvector

Output parameter type: cstring

Code example:

gaussdb=# SELECT bool_vector_out(boolvector('[1,1,1]'));

bool_vector_send

Function: Specifies the boolvector input conversion function (binary format).

Input parameter type: boolvector

Output parameter type: bytea

Code example:

gaussdb=# SELECT bool_vector_send(boolvector('[1,1,1]'));

bool_vector_recv

Function: Specifies the boolvector output conversion function (binary format).

Type of input parameter 1: internal

Type of input parameter 2: OID

Type of input parameter 3: int4

Output parameter type: boolvector

Code example:

-- This is a system function and cannot be called by SQL statements.

bool_vector_typmod_in

Function: Specifies the boolvector input type modifier function.

Input parameter type: cstring[]

Output parameter type: integer

Code example:

gaussdb=# SELECT bool_vector_typmod_in( '{1}' );
NOTE:
  • The vector data type does not support null, nan, or inf as elements. If a vector contains NULL values, the database reports an error.
  • When a vector data type is inserted, NULL cannot be used as the inserted value. When a NULL value is inserted as the vector data, the database reports an error.
  • Elements of the boolvector type can express Boolean data in t(T)/f(F), y(Y)/n(N), 1/0, true/false, yes/no, or on/off mode.
  • The boolvector type applies only to the equal-to operation and does not support comparison operations.

gs_vector_index_options

Function: Displays the hyperparameter values of related vector indexes.

Input parameter type: text

Output parameter type: text

Code example:

-- Create a table.
gaussdb=# CREATE TABLE t1 (id int unique,repr floatvector(960)) with (storage_type=astore);
Insert data.
gaussdb=# copy t1 from '/data/gist1w.txt' delimiter '^';
Create an index.
gaussdb=# CREATE INDEX test1v on t1 using gsdiskann (repr l2) with (pq_nseg=120,pq_nclus=64,queue_size=120,num_parallels=30,enable_pq=true,using_clustering_for_parallel=false); 

gaussdb=# SELECT gs_vector_index_options('test1v');

Operators for vector calculation focus on measuring similarity between vectors and binary operators of vectors.

<->

Function: Calculates the Euclidean distance (L2) between two vectors (floatvector).

Left parameter type: floatvector

Right parameter type: floatvector

Return type: double precision

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') <->  floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'<-> floatvector('[1,1,3,2]');

<+>

Function: Calculates the cosine distance between two vectors (floatvector).

Left parameter type: floatvector

Right parameter type: floatvector

Return type: double precision

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') <+>  floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'<+> floatvector('[1,1,3,2]');

<#>

Function: Calculates the Hamming distance between two vectors (floatvector).

Left parameter type: boolvector

Right parameter type: boolvector

Return type: double precision

Code example:

gaussdb=# SELECT boolvector('[1,0,1,0]') <#>  boolvector('[1,1,1,0]');
gaussdb=# SELECT '[1,0,1,0]'<#> boolvector('[1,1,1,0]');

+

Function: Calculates the bitwise addition of two vectors with the same dimension.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: floatvector

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') + floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'+ floatvector('[1,1,3,2]');

-

Function: Calculates the bitwise subtraction of two vectors with the same dimension.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: floatvector

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') + floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'+ floatvector('[1,1,3,2]');

<

Function: Compares the lexicographical order of two vectors with the same dimension.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: Boolean

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') < floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'< floatvector('[1,1,3,2]');

<=

Function: Compares the lexicographical order of two vectors with the same dimension.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: Boolean

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') <= floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'<= floatvector('[1,1,3,2]');

>

Function: Compares the lexicographical order of two vectors with the same dimension.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: Boolean

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') > floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'> floatvector('[1,1,3,2]');

>=

Function: Compares the lexicographical order of two vectors with the same dimension.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: Boolean

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') >= floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'>= floatvector('[1,1,3,2]');

=

Scenario 1:

Function: Determines whether two vectors with the same dimension are equal.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: Boolean

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') = floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'= floatvector('[1,1,3,2]');

Scenario 2:

Function: Determines whether two Boolean vectors with the same dimension are consistent.

Left parameter type: boolvector

Right parameter type: boolvector

Return type: Boolean

Code example:

gaussdb=# SELECT boolvector('[1,0,1,0]') =  boolvector('[1,1,1,0]');
gaussdb=# SELECT '[1,0,1,0]' =  boolvector('[1,1,1,0]');

<>

Function: Determines whether two vectors with the same dimension are unequal.

Left parameter type: floatvector

Right parameter type: floatvector

Return type: Boolean

Code example:

gaussdb=# SELECT floatvector('[1,1,3,2]') <> floatvector('[1,1,3,2]');
gaussdb=# SELECT '[1,2,3,2]'<> floatvector('[1,1,3,2]');
NOTE:

If the vector element value is large, the intermediate calculation result may overflow the single-precision range during distance calculation. As a result, the distance result is NAN or INF.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback