pgvector HNSW index
Pgvector provides a graph-based indexing algorithm based on the popular HNSW algorithm.
To create this index, run:
The above command creates the index using smart defaults. There are a number of parameters you could tune to adjust the accuracy/speed trade-off.
The parameters you can set at index build time are:
| Parameter name | Description | Default value |
|---|---|---|
m | Represents the maximum number of connections per layer. Think of these connections as edges created for each node during graph construction. Increasing m increases accuracy but also increases index build time and size. | 16 |
ef_construction | Represents the size of the dynamic candidate list for constructing the graph. It influences the trade-off between index quality and construction speed. Increasing ef_construction enables more accurate search results at the expense of lengthier index build times. | 64 |
To set these parameters, you could run:
You can also set a parameter to control the accuracy vs. query speed trade-off at query time. The parameter is set in the search() function using the query_params argument. You can set the ef_search(default: 40). This parameter specifies the size of the dynamic candidate list used during search. Higher values improve query accuracy while making the query slower.
You can specify this value during search as follows:
To drop the index run: