Compare commits

..

5 Commits
bound2 ... bas

Author SHA1 Message Date
Andrew Kane
bb72a6c063 Test BufferAccessStrategy [skip ci] 2023-04-10 22:07:58 -07:00
Andrew Kane
f32f695844 Improved notice [skip ci] 2023-04-10 21:31:33 -07:00
Andrew Kane
1b013a94f7 Added notice when index created with little data [skip ci] 2023-04-10 21:28:24 -07:00
Andrew Kane
00148dfa1f Improved indexing docs [skip ci] 2023-04-10 21:12:25 -07:00
Andrew Kane
67fc791d95 Improved indexing docs [skip ci] 2023-04-10 21:04:46 -07:00
6 changed files with 20 additions and 20 deletions

View File

@@ -1,3 +1,7 @@
## 0.4.2 (unreleased)
- Added notice when index created with little data
## 0.4.1 (2023-03-21)
- Improved performance of cosine distance

View File

@@ -153,15 +153,11 @@ By default, pgvector performs exact nearest neighbor search, which provides perf
You can add an index to use approximate nearest neighbor search, which trades some recall for performance. Unlike typical indexes, you will see different results for queries after adding an approximate index.
Two keys to achieving good recall are:
Three keys to achieving good recall are:
1. Create the index *after* the table has some data
2. Choose an appropriate number of lists (lower is better for recall, higher is better for speed)
A good place to start is:
- `rows / 1000` for up to 1M rows
- `sqrt(rows)` for over 1M rows
2. Choose an appropriate number of lists (a good place to start is `rows / 1000` for up to 1M rows and `sqrt(rows)` for over 1M rows)
3. When querying, specify an appropriate number of [probes](#query-options) (higher is better for recall, lower is better for speed)
Add an index for each distance function you want to use.
@@ -190,7 +186,7 @@ Vectors with up to 2,000 dimensions can be indexed.
Specify the number of probes (1 by default)
```sql
SET ivfflat.probes = 1;
SET ivfflat.probes = 10;
```
A higher value provides better recall at the cost of speed, and it can be set to the number of lists for exact nearest neighbor search (at which point the planner wont use the index)
@@ -199,7 +195,7 @@ Use `SET LOCAL` inside a transaction to set it for a single query
```sql
BEGIN;
SET LOCAL ivfflat.probes = 1;
SET LOCAL ivfflat.probes = 10;
SELECT ...
COMMIT;
```

View File

@@ -431,8 +431,18 @@ ComputeCenters(IvfflatBuildState * buildstate)
/* TODO Ensure within maintenance_work_mem */
buildstate->samples = VectorArrayInit(numSamples, buildstate->dimensions);
if (buildstate->heap != NULL)
{
SampleRows(buildstate);
if (buildstate->samples->length < buildstate->lists)
{
ereport(NOTICE,
(errmsg("ivfflat index created with little data"),
errdetail("this will cause poor recall"),
errhint("drop the index until the table has more data")));
}
}
/* Calculate centers */
IvfflatBench("k-means", IvfflatKmeans(buildstate->index, buildstate->samples, buildstate->centers));

View File

@@ -13,7 +13,6 @@
#endif
int ivfflat_probes;
int ivfflat_bound;
static relopt_kind ivfflat_relopt_kind;
/*
@@ -33,10 +32,6 @@ _PG_init(void)
DefineCustomIntVariable("ivfflat.probes", "Sets the number of probes",
"Valid range is 1..lists.", &ivfflat_probes,
1, 1, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
DefineCustomIntVariable("ivfflat.bound", "Sets the max results from index (experimental)",
NULL, &ivfflat_bound,
0, 0, INT_MAX, PGC_USERSET, 0, NULL, NULL, NULL);
}
/*

View File

@@ -78,7 +78,6 @@
/* Variables */
extern int ivfflat_probes;
extern int ivfflat_bound;
/* Exported functions */
PGDLLEXPORT void _PG_init(void);

View File

@@ -124,11 +124,7 @@ GetScanItems(IndexScanDesc scan, Datum value)
*
* See postgres/src/backend/storage/buffer/README for description
*/
BufferAccessStrategy bas = GetAccessStrategy(BAS_BULKREAD);
/* Set the max number of results */
if (ivfflat_bound > 0)
tuplesort_set_bound(so->sortstate, ivfflat_bound);
BufferAccessStrategy bas = GetAccessStrategy(BAS_NORMAL);
/* Search closest probes lists */
while (!pairingheap_is_empty(so->listQueue))