mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 23:26:55 +08:00
Fixed item size [skip ci]
This commit is contained in:
@@ -365,8 +365,7 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
|
|||||||
|
|
||||||
buildstate->slot = MakeSingleTupleTableSlot(buildstate->tupdesc, &TTSOpsVirtual);
|
buildstate->slot = MakeSingleTupleTableSlot(buildstate->tupdesc, &TTSOpsVirtual);
|
||||||
|
|
||||||
/* TODO Fix item size */
|
buildstate->centers = VectorArrayInit(buildstate->lists, buildstate->dimensions, buildstate->typeInfo->itemSize(buildstate->dimensions));
|
||||||
buildstate->centers = VectorArrayInit(buildstate->lists, buildstate->dimensions, VECTOR_SIZE(buildstate->dimensions));
|
|
||||||
buildstate->listInfo = palloc(sizeof(ListInfo) * buildstate->lists);
|
buildstate->listInfo = palloc(sizeof(ListInfo) * buildstate->lists);
|
||||||
|
|
||||||
buildstate->tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
|
buildstate->tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ typedef struct IvfflatTypeInfo
|
|||||||
{
|
{
|
||||||
int maxDimensions;
|
int maxDimensions;
|
||||||
Datum (*normalize) (PG_FUNCTION_ARGS);
|
Datum (*normalize) (PG_FUNCTION_ARGS);
|
||||||
|
Size (*itemSize) (int dimensions);
|
||||||
void (*updateCenter) (Pointer v, int dimensions, float *x);
|
void (*updateCenter) (Pointer v, int dimensions, float *x);
|
||||||
void (*sumCenter) (Pointer v, float *x);
|
void (*sumCenter) (Pointer v, float *x);
|
||||||
} IvfflatTypeInfo;
|
} IvfflatTypeInfo;
|
||||||
|
|||||||
@@ -229,6 +229,24 @@ PGDLLEXPORT Datum l2_normalize(PG_FUNCTION_ARGS);
|
|||||||
PGDLLEXPORT Datum halfvec_l2_normalize(PG_FUNCTION_ARGS);
|
PGDLLEXPORT Datum halfvec_l2_normalize(PG_FUNCTION_ARGS);
|
||||||
PGDLLEXPORT Datum sparsevec_l2_normalize(PG_FUNCTION_ARGS);
|
PGDLLEXPORT Datum sparsevec_l2_normalize(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
|
static Size
|
||||||
|
VectorItemSize(int dimensions)
|
||||||
|
{
|
||||||
|
return VECTOR_SIZE(dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Size
|
||||||
|
HalfvecItemSize(int dimensions)
|
||||||
|
{
|
||||||
|
return HALFVEC_SIZE(dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Size
|
||||||
|
BitItemSize(int dimensions)
|
||||||
|
{
|
||||||
|
return VARBITTOTALLEN(dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
VectorUpdateCenter(Pointer v, int dimensions, float *x)
|
VectorUpdateCenter(Pointer v, int dimensions, float *x)
|
||||||
{
|
{
|
||||||
@@ -309,6 +327,7 @@ IvfflatGetTypeInfo(Relation index)
|
|||||||
static const IvfflatTypeInfo typeInfo = {
|
static const IvfflatTypeInfo typeInfo = {
|
||||||
.maxDimensions = IVFFLAT_MAX_DIM,
|
.maxDimensions = IVFFLAT_MAX_DIM,
|
||||||
.normalize = l2_normalize,
|
.normalize = l2_normalize,
|
||||||
|
.itemSize = VectorItemSize,
|
||||||
.updateCenter = VectorUpdateCenter,
|
.updateCenter = VectorUpdateCenter,
|
||||||
.sumCenter = VectorSumCenter
|
.sumCenter = VectorSumCenter
|
||||||
};
|
};
|
||||||
@@ -326,6 +345,7 @@ ivfflat_halfvec_support(PG_FUNCTION_ARGS)
|
|||||||
static const IvfflatTypeInfo typeInfo = {
|
static const IvfflatTypeInfo typeInfo = {
|
||||||
.maxDimensions = IVFFLAT_MAX_DIM * 2,
|
.maxDimensions = IVFFLAT_MAX_DIM * 2,
|
||||||
.normalize = halfvec_l2_normalize,
|
.normalize = halfvec_l2_normalize,
|
||||||
|
.itemSize = HalfvecItemSize,
|
||||||
.updateCenter = HalfvecUpdateCenter,
|
.updateCenter = HalfvecUpdateCenter,
|
||||||
.sumCenter = HalfvecSumCenter
|
.sumCenter = HalfvecSumCenter
|
||||||
};
|
};
|
||||||
@@ -340,6 +360,7 @@ ivfflat_bit_support(PG_FUNCTION_ARGS)
|
|||||||
static const IvfflatTypeInfo typeInfo = {
|
static const IvfflatTypeInfo typeInfo = {
|
||||||
.maxDimensions = IVFFLAT_MAX_DIM * 32,
|
.maxDimensions = IVFFLAT_MAX_DIM * 32,
|
||||||
.normalize = NULL,
|
.normalize = NULL,
|
||||||
|
.itemSize = BitItemSize,
|
||||||
.updateCenter = BitUpdateCenter,
|
.updateCenter = BitUpdateCenter,
|
||||||
.sumCenter = BitSumCenter
|
.sumCenter = BitSumCenter
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user