pgvector.git / summary / log / commit / refs
commit ba18942fcff8aa846df284b0b10517ec85d0e36b
Author: Andrew Kane <andrew@ankane.org>
Date: Wed Mar 27 23:41:17 2024 +0000
Removed normvec from IVFFlat for simplicity (no difference in performance)
src/ivfbuild.c | 8 ++------
src/ivfflat.h | 3 +--
src/ivfinsert.c | 2 +-
src/ivfscan.c | 2 +-
src/ivfutils.c | 6 ++----
5 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/src/ivfbuild.c b/src/ivfbuild.c
index c4f4d4bd..4c52d9f6 100644
--- a/src/ivfbuild.c
+++ b/src/ivfbuild.c
@@ -57,7 +57,7 @@ AddSample(Datum *values, IvfflatBuildState * buildstate)
*/
if (buildstate->kmeansnormprocinfo != NULL)
{
- if (!IvfflatNormValue(buildstate->kmeansnormprocinfo, buildstate->collation, &value, buildstate->normvec))
+ if (!IvfflatNormValue(buildstate->kmeansnormprocinfo, buildstate->collation, &value))
return;
}
@@ -153,7 +153,7 @@ AddTupleToSort(Relation index, ItemPointer tid, Datum *values, IvfflatBuildState
/* Normalize if needed */
if (buildstate->normprocinfo != NULL)
{
- if (!IvfflatNormValue(buildstate->normprocinfo, buildstate->collation, &value, buildstate->normvec))
+ if (!IvfflatNormValue(buildstate->normprocinfo, buildstate->collation, &value))
return;
}
@@ -356,9 +356,6 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
buildstate->centers = VectorArrayInit(buildstate->lists, buildstate->dimensions);
buildstate->listInfo = palloc(sizeof(ListInfo) * buildstate->lists);
- /* Reuse for each tuple */
- buildstate->normvec = InitVector(buildstate->dimensions);
-
buildstate->tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
"Ivfflat build temporary context",
ALLOCSET_DEFAULT_SIZES);
@@ -380,7 +377,6 @@ FreeBuildState(IvfflatBuildState * buildstate)
{
VectorArrayFree(buildstate->centers);
pfree(buildstate->listInfo);
- pfree(buildstate->normvec);
#ifdef IVFFLAT_KMEANS_DEBUG
pfree(buildstate->listSums);
diff --git a/src/ivfflat.h b/src/ivfflat.h
index e27420b9..422967f1 100644
--- a/src/ivfflat.h
+++ b/src/ivfflat.h
@@ -172,7 +172,6 @@ typedef struct IvfflatBuildState
VectorArray samples;
VectorArray centers;
ListInfo *listInfo;
- Vector *normvec;
#ifdef IVFFLAT_KMEANS_DEBUG
double inertia;
@@ -267,7 +266,7 @@ void VectorArrayFree(VectorArray arr);
void PrintVectorArray(char *msg, VectorArray arr);
void IvfflatKmeans(Relation index, VectorArray samples, VectorArray centers);
FmgrInfo *IvfflatOptionalProcInfo(Relation index, uint16 procnum);
-bool IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result);
+bool IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value);
int IvfflatGetLists(Relation index);
void IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions);
void IvfflatUpdateList(Relation index, ListInfo listInfo, BlockNumber insertPage, BlockNumber originalInsertPage, BlockNumber startPage, ForkNumber forkNum);
diff --git a/src/ivfinsert.c b/src/ivfinsert.c
index 342cca7e..2d8d4c3b 100644
--- a/src/ivfinsert.c
+++ b/src/ivfinsert.c
@@ -85,7 +85,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, R
normprocinfo = IvfflatOptionalProcInfo(index, IVFFLAT_NORM_PROC);
if (normprocinfo != NULL)
{
- if (!IvfflatNormValue(normprocinfo, index->rd_indcollation[0], &value, NULL))
+ if (!IvfflatNormValue(normprocinfo, index->rd_indcollation[0], &value))
return;
}
diff --git a/src/ivfscan.c b/src/ivfscan.c
index 9b0e03e3..66b3ae63 100644
--- a/src/ivfscan.c
+++ b/src/ivfscan.c
@@ -293,7 +293,7 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
/* Fine if normalization fails */
if (so->normprocinfo != NULL)
- IvfflatNormValue(so->normprocinfo, so->collation, &value, NULL);
+ IvfflatNormValue(so->normprocinfo, so->collation, &value);
}
IvfflatBench("GetScanLists", GetScanLists(scan, value));
diff --git a/src/ivfutils.c b/src/ivfutils.c
index a8746f7f..587a97e4 100644
--- a/src/ivfutils.c
+++ b/src/ivfutils.c
@@ -75,16 +75,14 @@ IvfflatOptionalProcInfo(Relation index, uint16 procnum)
* if it's different than the original value
*/
bool
-IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result)
+IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value)
{
double norm = DatumGetFloat8(FunctionCall1Coll(procinfo, collation, *value));
if (norm > 0)
{
Vector *v = DatumGetVector(*value);
-
- if (result == NULL)
- result = InitVector(v->dim);
+ Vector *result = InitVector(v->dim);
for (int i = 0; i < v->dim; i++)
result->x[i] = v->x[i] / norm;
[parent: 8e59455c3c03]