Skip to content

Add support for QBit data type#99

Merged
alex-clickhouse merged 5 commits intomainfrom
qbit
Dec 27, 2025
Merged

Add support for QBit data type#99
alex-clickhouse merged 5 commits intomainfrom
qbit

Conversation

@alex-clickhouse
Copy link
Copy Markdown
Collaborator

No description provided.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...lickHouse.Driver/Formats/HttpParameterFormatter.cs 50.00% 0 Missing and 1 partial ⚠️
ClickHouse.Driver/Types/QBitType.cs 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for ClickHouse's QBit data type, which is a quantized vector type designed for efficient storage of embeddings with configurable precision. The implementation treats QBit as an array wrapper over Float32/Float64/BFloat16 element types, delegating to existing array serialization logic.

Key Changes:

  • Added QBitType class that implements the wire protocol (array format) and type parsing
  • Registered QBit as a parameterized type with binary decoder support
  • Added feature flag for version 25.10 with experimental setting enabled in tests

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
ClickHouse.Driver/Types/QBitType.cs Core type implementation handling QBit parsing, reading, and writing
ClickHouse.Driver/Types/TypeConverter.cs Registered QBitType as a parameterized type
ClickHouse.Driver/Types/BinaryTypeDecoder.cs Added binary decoder for QBit type index
ClickHouse.Driver/Formats/HttpParameterFormatter.cs Added HTTP parameter formatting for QBit arrays
ClickHouse.Driver/ADO/Feature.cs Added QBit feature flag for version 25.10
ClickHouse.Driver.Tests/Utilities/TestUtilities.cs Added test data samples and experimental setting enablement
ClickHouse.Driver.Tests/BulkCopy/BulkCopyTests.cs Added bulk copy tests for Float32, Float64, and BFloat16 variants
examples/Vector_001_QBitSimilaritySearch.cs Added comprehensive example demonstrating similarity search use case

Comment thread ClickHouse.Driver/Types/QBitType.cs Outdated
Comment thread ClickHouse.Driver/Types/QBitType.cs
Comment thread ClickHouse.Driver/Types/QBitType.cs Outdated
Comment thread ClickHouse.Driver/Types/QBitType.cs Outdated
Comment thread ClickHouse.Driver/Types/QBitType.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

{
// QBit wire format is Array(UnderlyingType)
var length = reader.Read7BitEncodedInt();
var data = Array.CreateInstance(ElementType.FrameworkType, Dimension);
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop iterates length times but the array is created with size Dimension. If length != Dimension, this will either leave array elements uninitialized (if length < Dimension) or throw an IndexOutOfRangeException (if length > Dimension). The array should be created with size length, not Dimension.

Suggested change
var data = Array.CreateInstance(ElementType.FrameworkType, Dimension);
if (length != Dimension)
{
throw new InvalidOperationException(
$"QBit element count mismatch. Expected {Dimension} elements but received {length} for type {this}.");
}
var data = Array.CreateInstance(ElementType.FrameworkType, length);

Copilot uses AI. Check for mistakes.
{
var elementType = FromByteCode(reader, typeSettings);
var dimension = reader.Read7BitEncodedInt();
return new QBitType { ElementType = elementType, Dimension = dimension };
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The QBitType instance is missing initialization of the UnderlyingArrayType property, which is used in the Write method. This will cause a NullReferenceException when writing QBit values via binary protocol. Initialize it with new ArrayType { UnderlyingType = elementType }.

Suggested change
return new QBitType { ElementType = elementType, Dimension = dimension };
return new QBitType
{
ElementType = elementType,
Dimension = dimension,
UnderlyingArrayType = new ArrayType { UnderlyingType = elementType }
};

Copilot uses AI. Check for mistakes.
Comment thread ClickHouse.Driver.Tests/BulkCopy/BulkCopyTests.cs
@alex-clickhouse alex-clickhouse merged commit 99c763a into main Dec 27, 2025
16 checks passed
@alex-clickhouse alex-clickhouse deleted the qbit branch December 27, 2025 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants