pgvector.git / summary / log / commit / refs
commit fa5e90585d96f50f06ffbf03db8535f55eb73732
Author: Andrew Kane <andrew@ankane.org>
Date: Sun Feb 13 05:23:53 2022 +0000
Added inertia
src/ivfbuild.c | 16 +++++++++++++++-
src/ivfflat.h | 4 ++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/ivfbuild.c b/src/ivfbuild.c
index 51c6a55a..65e4f385 100644
--- a/src/ivfbuild.c
+++ b/src/ivfbuild.c
@@ -170,6 +170,10 @@ BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
}
}
+#ifdef IVFFLAT_KMEANS_DEBUG
+ buildstate->inertia += minDistance;
+#endif
+
/* Create a virtual tuple */
ExecClearTuple(slot);
slot->tts_values[0] = Int32GetDatum(closestCenter);
@@ -350,6 +354,10 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
/* Reuse for each tuple */
buildstate->normvec = InitVector(buildstate->dimensions);
+
+#ifdef IVFFLAT_KMEANS_DEBUG
+ buildstate->inertia = 0;
+#endif
}
/*
@@ -502,8 +510,14 @@ CreateEntryPages(IvfflatBuildState * buildstate, ForkNumber forkNum)
#endif
}
- /* Sort and insert */
+ /* Sort */
tuplesort_performsort(buildstate->sortstate);
+
+#ifdef IVFFLAT_KMEANS_DEBUG
+ elog(INFO, "inertia: %.3e", buildstate->inertia);
+#endif
+
+ /* Insert */
InsertTuples(buildstate->index, buildstate, forkNum);
tuplesort_end(buildstate->sortstate);
}
diff --git a/src/ivfflat.h b/src/ivfflat.h
index 0533a836..9ec14f19 100644
--- a/src/ivfflat.h
+++ b/src/ivfflat.h
@@ -120,6 +120,10 @@ typedef struct IvfflatBuildState
ListInfo *listInfo;
Vector *normvec;
+#ifdef IVFFLAT_KMEANS_DEBUG
+ double inertia;
+#endif
+
/* Sampling */
BlockSamplerData bs;
ReservoirStateData rstate;
[parent: 71d2908be185]