mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 12:07:34 +08:00
Compare commits
1 Commits
ivfflat-qu
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6420355c5 |
@@ -1233,7 +1233,7 @@ Note: Replace `18` with your Postgres server version
|
||||
Install the FreeBSD package with:
|
||||
|
||||
```sh
|
||||
pkg install postgresql17-pgvector
|
||||
pkg install postgresql18-pgvector
|
||||
```
|
||||
|
||||
or the port with:
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "fmgr.h"
|
||||
#include "ivfflat.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
@@ -106,44 +105,16 @@ NormCenters(const IvfflatTypeInfo * typeInfo, Oid collation, VectorArray centers
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if vector array contains a vector
|
||||
*/
|
||||
static bool
|
||||
VectorArrayContains(VectorArray arr, Pointer val)
|
||||
{
|
||||
Datum d = PointerGetDatum(val);
|
||||
|
||||
for (int i = 0; i < arr->length; i++)
|
||||
{
|
||||
if (datumIsEqual(d, PointerGetDatum(VectorArrayGet(arr, i)), false, -1))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Quick approach if we have little data
|
||||
* Quick approach if we have no data
|
||||
*/
|
||||
static void
|
||||
QuickCenters(Relation index, VectorArray samples, VectorArray centers, const IvfflatTypeInfo * typeInfo)
|
||||
RandomCenters(Relation index, VectorArray centers, const IvfflatTypeInfo * typeInfo)
|
||||
{
|
||||
int dimensions = centers->dim;
|
||||
FmgrInfo *normprocinfo = IvfflatOptionalProcInfo(index, IVFFLAT_KMEANS_NORM_PROC);
|
||||
Oid collation = index->rd_indcollation[0];
|
||||
float *x = (float *) palloc(sizeof(float) * dimensions);
|
||||
|
||||
/* Fill with unique samples (already normalized) */
|
||||
for (int i = 0; i < samples->length; i++)
|
||||
{
|
||||
Pointer sample = VectorArrayGet(samples, i);
|
||||
|
||||
if (!VectorArrayContains(centers, sample))
|
||||
{
|
||||
VectorArraySet(centers, centers->length, sample);
|
||||
centers->length++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill with random data */
|
||||
while (centers->length < centers->maxlen)
|
||||
{
|
||||
@@ -577,8 +548,8 @@ IvfflatKmeans(Relation index, VectorArray samples, VectorArray centers, const Iv
|
||||
ALLOCSET_DEFAULT_SIZES);
|
||||
MemoryContext oldCtx = MemoryContextSwitchTo(kmeansCtx);
|
||||
|
||||
if (samples->length <= centers->maxlen)
|
||||
QuickCenters(index, samples, centers, typeInfo);
|
||||
if (samples->length == 0)
|
||||
RandomCenters(index, centers, typeInfo);
|
||||
else
|
||||
ElkanKmeans(index, samples, centers, typeInfo, memoryUsed);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user