Skip to main content

Vector Searches

Vector searches use the HNSW index for fast retrieval, providing approximate results with a typical recall rate of over 95%.


Syntax

Following is an example using the Euclidean distance:

SELECT ID, <vector_column_name> <-> '[0.1,0.2,0.3...]' as distance FROM <table_name> ORDER BY <order_column_name> <-> '[0.1,0.2,0.3...]' LIMIT <top_k>;

Usage notes

  • If no index is created, approximate searches will default to exact searches, which are slower but ensure 100% accuracy.

  • To utilize vector index acceleration, the ORDER BY clause must include operators like <->, <#>, or <=>, paired with the appropriate vector index and distance metric. Without this pairing, acceleration cannot be applied. For more details on supported operators and usage, refer to Vector Indexing.


Examples

This example uses the knowledge base from Vector Indexing to retrieve source documents through vector-based text searches.

Following is the query text:

SELECT id, chunk, intime, url, embedding <-> '[10,2.0,..., 1536.0]' as distance FROM docs
ORDER BY
embedding <-> '[10,2.0,..., 1536.0]'
LIMIT 100;