Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **Quantizer rescore factor**: `RescoreFactor` on the PQ, BQ, SQ and RQ quantizers and `RescoreLimit` on PQ. Requires Weaviate ≥ 1.41.0. Older servers ignore them.

---

## [1.2.0] — 2026-08-21
Expand Down
107 changes: 107 additions & 0 deletions src/Weaviate.Client.Tests/Integration/TestCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ public async Task Test_Collections_Export_Cases(string key)
expected.ReplicationConfig.AsyncEnabled = expected.ReplicationConfig.Factor > 1;
}

// Weaviate 1.41+ reports an unset rescore factor or PQ rescore limit as -1.
foreach (var vc in export!.VectorConfig.Values)
{
switch (
(vc.VectorIndexConfig as VectorIndex.HNSW)?.Quantizer
?? (vc.VectorIndexConfig as VectorIndex.Flat)?.Quantizer
)
{
case VectorIndex.Quantizers.BQ bq:
bq.RescoreFactor = null;
break;
case VectorIndex.Quantizers.PQ pq:
pq.RescoreFactor = null;
pq.RescoreLimit = null;
break;
case VectorIndex.Quantizers.SQ sq:
sq.RescoreFactor = null;
break;
}
}

Assert.Equal(expected, export);
}
#endif
Expand Down Expand Up @@ -1395,6 +1416,92 @@ public async Task Test_hnsw_centered_rq4()
Assert.Equal(5000, rqQuantizer.TrainingLimit);
}

/// <summary>
/// Tests that an HNSW quantizer's rescore factor is set on create and changed on update
/// </summary>
[Theory]
[InlineData("bq")]
[InlineData("pq")]
[InlineData("sq")]
[InlineData("rq")]
public async Task Test_hnsw_quantizer_rescore_factor(string type)
{
RequireVersion(
"1.41.0",
message: "Rescore factor only supported in server version 1.41.0+"
);

VectorIndexConfig.QuantizerConfigBase Quantizer(double factor) =>
type switch
{
"bq" => new VectorIndex.Quantizers.BQ { RescoreLimit = 30, RescoreFactor = factor },
"pq" => new VectorIndex.Quantizers.PQ
{
Centroids = 256,
Encoder = new VectorIndex.Quantizers.PQ.EncoderConfig
{
Type = VectorIndex.Quantizers.EncoderType.Tile,
Distribution = VectorIndex.Quantizers.DistributionType.Normal,
},
TrainingLimit = 100000,
RescoreLimit = 30,
RescoreFactor = factor,
},
"sq" => new VectorIndex.Quantizers.SQ
{
TrainingLimit = 100000,
RescoreLimit = 30,
RescoreFactor = factor,
},
_ => new VectorIndex.Quantizers.RQ
{
Bits = 8,
RescoreLimit = 30,
RescoreFactor = factor,
},
};
var collection = await CollectionFactory(
vectorConfig:
[
Configure.Vector(
"default",
t => t.SelfProvided(),
new VectorIndex.HNSW { Quantizer = Quantizer(2.5) }
),
]
);

async Task<VectorIndexConfig.QuantizerConfigBase?> GetQuantizer()
{
var config = await collection.Config.Get(TestContext.Current.CancellationToken);
var hnsw = config?.VectorConfig["default"].VectorIndexConfig as VectorIndex.HNSW;
Assert.NotNull(hnsw?.Quantizer);
Assert.Equal(type, hnsw.Quantizer.Type);
return hnsw.Quantizer;
}

static (int? Limit, double? Factor) Rescore(VectorIndexConfig.QuantizerConfigBase? q) =>
q switch
{
VectorIndex.Quantizers.BQ bq => (bq.RescoreLimit, bq.RescoreFactor),
VectorIndex.Quantizers.PQ pq => (pq.RescoreLimit, pq.RescoreFactor),
VectorIndex.Quantizers.SQ sq => (sq.RescoreLimit, sq.RescoreFactor),
VectorIndex.Quantizers.RQ rq => (rq.RescoreLimit, rq.RescoreFactor),
_ => (null, null),
};

Assert.Equal((30, 2.5), Rescore(await GetQuantizer()));

await collection.Config.Update(
c =>
c.VectorConfig["default"]
.VectorIndexConfig.UpdateHNSW(vic => vic.Quantizer = Quantizer(4)),
TestContext.Current.CancellationToken
);

Assert.Equal((30, 4.0), Rescore(await GetQuantizer()));
}

/// <summary>
/// Tests that test flat rq
/// </summary>
Expand Down
53 changes: 53 additions & 0 deletions src/Weaviate.Client.Tests/Unit/TestVectorIndexConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,57 @@ public void VectorIndexConfig_RQ_Centering_Without_4_Bits_Throws()

_ = VectorIndexSerialization.SerializeHnsw(trainingLimitOnly);
}

/// <summary>Tests that a quantizer's rescoreFactor (and PQ rescoreLimit) serializes and round-trips.</summary>
[Theory]
[InlineData("bq")]
[InlineData("pq")]
[InlineData("sq")]
[InlineData("rq")]
public void VectorIndexConfig_HNSW_Quantizer_RescoreFactor_Roundtrip(string type)
{
VectorIndexConfig.QuantizerConfigBase quantizer = type switch
{
"bq" => new VectorIndex.Quantizers.BQ { RescoreFactor = 2.5 },
"pq" => new VectorIndex.Quantizers.PQ { RescoreFactor = 2.5, RescoreLimit = 30 },
"sq" => new VectorIndex.Quantizers.SQ { RescoreFactor = 2.5 },
_ => new VectorIndex.Quantizers.RQ { Bits = 8, RescoreFactor = 2.5 },
};

var json = VectorIndexSerialization.SerializeHnsw(
new VectorIndex.HNSW { Quantizer = quantizer }
);

using var doc = JsonDocument.Parse(json);
var quantizerJson = doc.RootElement.GetProperty(type);
Assert.Equal(2.5, quantizerJson.GetProperty("rescoreFactor").GetDouble());
if (type == "pq")
{
Assert.Equal(30, quantizerJson.GetProperty("rescoreLimit").GetInt32());
}

var dict = JsonSerializer.Deserialize<Dictionary<string, object>>(
json,
Weaviate.Client.Rest.WeaviateRestClient.RestJsonSerializerOptions
);
var roundtripped = (VectorIndex.HNSW?)VectorIndexSerialization.Factory("hnsw", dict);

Assert.Equal(type, roundtripped?.Quantizer?.Type);
switch (roundtripped?.Quantizer)
{
case VectorIndex.Quantizers.BQ bq:
Assert.Equal(2.5, bq.RescoreFactor);
break;
case VectorIndex.Quantizers.PQ pq:
Assert.Equal(2.5, pq.RescoreFactor);
Assert.Equal(30, pq.RescoreLimit);
break;
case VectorIndex.Quantizers.SQ sq:
Assert.Equal(2.5, sq.RescoreFactor);
break;
case VectorIndex.Quantizers.RQ rq:
Assert.Equal(2.5, rq.RescoreFactor);
break;
}
}
}
29 changes: 29 additions & 0 deletions src/Weaviate.Client/Models/VectorIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public record BQ : QuantizerConfigFlat
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public int RescoreLimit { get; set; }

/// <summary>
/// Gets or sets the rescore factor. Weaviate rescores at least the query limit multiplied
/// by this factor. The server reports -1 when it is unset.
/// </summary>
public double? RescoreFactor { get; set; }

/// <summary>
/// Gets the type identifier for the quantizer.
/// </summary>
Expand All @@ -242,6 +248,12 @@ public record RQ : QuantizerConfigFlat
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public int RescoreLimit { get; set; }

/// <summary>
/// Gets or sets the rescore factor. Weaviate rescores at least the query limit multiplied
/// by this factor. The server reports -1 when it is unset.
/// </summary>
public double? RescoreFactor { get; set; }

/// <summary>
/// Gets or sets the number of bits for quantization.
/// </summary>
Expand Down Expand Up @@ -288,6 +300,12 @@ public record SQ : QuantizerConfigBase
/// </summary>
public int RescoreLimit { get; set; }

/// <summary>
/// Gets or sets the rescore factor. Weaviate rescores at least the query limit multiplied
/// by this factor. The server reports -1 when it is unset.
/// </summary>
public double? RescoreFactor { get; set; }

/// <summary>
/// Gets or sets the training limit for the quantizer.
/// </summary>
Expand Down Expand Up @@ -353,6 +371,17 @@ public record EncoderConfig
/// </summary>
public int TrainingLimit { get; set; }

/// <summary>
/// Gets or sets the limit for rescoring operations.
/// </summary>
public int? RescoreLimit { get; set; }

/// <summary>
/// Gets or sets the rescore factor. Weaviate rescores at least the query limit multiplied
/// by this factor. The server reports -1 when it is unset.
/// </summary>
public double? RescoreFactor { get; set; }

/// <summary>
/// Gets the type identifier for the quantizer.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Weaviate.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,13 @@ Weaviate.Client.Models.VectorIndex.Quantizers.RQ.Centering.get -> bool
Weaviate.Client.Models.VectorIndex.Quantizers.RQ.Centering.set -> void
Weaviate.Client.Models.VectorIndex.Quantizers.RQ.TrainingLimit.get -> int
Weaviate.Client.Models.VectorIndex.Quantizers.RQ.TrainingLimit.set -> void
Weaviate.Client.Models.VectorIndex.Quantizers.BQ.RescoreFactor.get -> double?
Weaviate.Client.Models.VectorIndex.Quantizers.BQ.RescoreFactor.set -> void
Weaviate.Client.Models.VectorIndex.Quantizers.PQ.RescoreFactor.get -> double?
Weaviate.Client.Models.VectorIndex.Quantizers.PQ.RescoreFactor.set -> void
Weaviate.Client.Models.VectorIndex.Quantizers.PQ.RescoreLimit.get -> int?
Weaviate.Client.Models.VectorIndex.Quantizers.PQ.RescoreLimit.set -> void
Weaviate.Client.Models.VectorIndex.Quantizers.RQ.RescoreFactor.get -> double?
Weaviate.Client.Models.VectorIndex.Quantizers.RQ.RescoreFactor.set -> void
Weaviate.Client.Models.VectorIndex.Quantizers.SQ.RescoreFactor.get -> double?
Weaviate.Client.Models.VectorIndex.Quantizers.SQ.RescoreFactor.set -> void
Loading