Skip to content

Docs: use Array(BFloat16) for vector embeddings in vector-search examples - #111156

Merged
rschu1ze merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/docs-embeddings-bfloat16
Jul 21, 2026
Merged

rschu1ze merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/docs-embeddings-bfloat16

Conversation

@groeneai

@groeneai groeneai commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Documentation (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Float32 is an anti-pattern for storing embeddings. BFloat16 halves storage at negligible precision loss and is already the default HNSW quantization, and the vector-search guide already lists Array(BFloat16) as a supported vector-column type.

This switches the embedding-column CREATE TABLE examples in the vector-search guide (annindexes.md) from Array(Float32) to Array(BFloat16): exact-search example, compression-tuning example, and approximate-search example. The two affected example output blocks are regenerated to the real BFloat16-rounded values.

Left unchanged on purpose (Float32 is intentional there, not the anti-pattern): the type enumerations of valid vector-column types, the Array(Float*) templates, the deliberate Float32-vs-BFloat16 storage-size/precision comparisons, and the binary reinterpret(..., 'Array(Float32)') transfer snippet.

Follow-up from @ alexey-milovidov's review on #111128 (Float32 embeddings are an anti-pattern; change across the docs).

Remaining sweep items, deferred so this PR stays fully verified:

Version info

  • Merged into: 26.7.1.1279 (included in 26.7 and later)

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A (docs). The examples recommended Array(Float32) for embedding storage, the documented anti-pattern.
b Root cause explained? Yes. Float32 embeddings are an anti-pattern; BFloat16 halves storage at negligible precision loss and is the default HNSW quantization. This file already lists Array(BFloat16) as a supported vector-column type.
c Fix matches root cause? Yes. Flips the vector-column type in the embedding examples from Float32 to BFloat16.
d Test intent preserved / new tests? N/A (docs). Examples still demonstrate exact + approximate vector search; only storage type and regenerated output values change.
e Demonstrated both directions? Yes. clickhouse-local (master) confirms Array(BFloat16) parses/creates plain, with CODEC(NONE), and with a vector_similarity index, and that the shown output values are the actual BFloat16-rounded results ([0,2] / [0,2.09375] / [0,2.1875]) rather than the old Float32 values.
f General, not a narrow patch? Yes. All three embedding CREATE TABLE examples in the file were flipped (exact-search, compression-tuning, approximate-search), not just one.
g Generalizes across inputs/wrappers? N/A (no type-gating code). Scope covers the full docs occurrence matrix; non-embedding Float32 uses (enumerations, Array(Float*) templates, size/precision contrasts, binary reinterpret snippet, QBit precision pedagogy) are intentionally left as-is.
h Backward compatible? N/A. Documentation only, no code/setting/format change.
i Invariants/contracts preserved? N/A (no code). Regenerated output blocks are byte-exact real server output, so the edited examples stay internally consistent.

Session id: cron:clickhouse-author-slot-0:20260720-234300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Independent second-model diff review of the committed change (SHA 6ae548c4722cd).

Findings: none (0 blockers / 0 majors / 0 nits).

Approach review before writing edits raised one item, which was accepted and shaped the scope:

  • [Major, AGREE] A dataset-page sweep would ship real-data outputs and processed-size figures inconsistent with the changed storage type (e.g. dbpedia Processed 1.00 million rows, 6.22 GB is the Float32 read size). Those outputs need a cluster re-run to regenerate honestly. Resolution: this PR is limited to the reference-guide examples, which are fully verifiable offline; the sample-dataset pages are deferred and called out in the PR description.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @shankar-iyer — could you review this docs-only change? It switches the embedding-column examples in the vector-search guide from Array(Float32) to Array(BFloat16) (with regenerated example outputs), following the anti-pattern feedback on #111128.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4f393a6]

Summary: ✅


AI Review

Summary

This PR tries to switch the vector-search guide examples from Array(Float32) to Array(BFloat16) and rewrites part of the Quantized-codec section, but the current merge result is still not internally consistent. Three previously reported documentation mismatches are still present in docs/en/engines/table-engines/mergetree-family/annindexes.md, and the corresponding Mintlify reference page was not updated at all, so the repo now has two conflicting versions of the same guidance.

Findings

⚠️ Majors

  • [docs/en/engines/table-engines/mergetree-family/annindexes.md:29] The PR only updates the legacy Docusaurus page. The same slug is mapped to docs/reference/engines/table-engines/mergetree-family/annindexes.mdx in docs/_migration/slug-map.csv:365, and that Mintlify reference page is still on the old Array(Float32) recommendation and examples. The result is two contradictory documentation trees for the same topic.
  • [docs/en/engines/table-engines/mergetree-family/annindexes.md:90] BFloat32 is not a ClickHouse type. This placeholder now points readers at a nonexistent schema even though the surrounding text still documents Array(BFloat16) as the supported 16-bit option.
  • [docs/en/engines/table-engines/mergetree-family/annindexes.md:63, docs/en/engines/table-engines/mergetree-family/annindexes.md:628] Both result blocks still show the old Float32 values after the examples were switched to Array(BFloat16). The shipped reference output for the same data set is [0,2], [0,2.09375], [0,2.1875] (tests/queries/0_stateless/02354_vector_search_queries.reference:421-424), so the guide currently shows results users cannot reproduce.
  • [docs/en/engines/table-engines/mergetree-family/annindexes.md:391] The EXPLAIN header = 1 block was rewritten to BFloat16, but the implementation still exposes _distance Float32 on this path (tests/queries/0_stateless/02354_vector_search_rescoring.reference:6, :42-43, and the untouched Mintlify page at docs/reference/engines/table-engines/mergetree-family/annindexes.mdx:392). The guide now documents an EXPLAIN output that disagrees with the actual query plan.
Final Verdict

⚠️ Not ready to merge. The example outputs and EXPLAIN block still need to be brought back in sync with actual behavior, and the equivalent Mintlify reference page needs the same BFloat16 update so the two docs trees do not diverge.

@clickhouse-gh clickhouse-gh Bot added the pr-documentation Documentation PRs for the specific code PR label Jul 21, 2026
@rschu1ze rschu1ze self-assigned this Jul 21, 2026
@rschu1ze
rschu1ze force-pushed the groeneai/docs-embeddings-bfloat16 branch from 6ae548c to 063b7f9 Compare July 21, 2026 09:08
@rschu1ze

Copy link
Copy Markdown
Member

@groeneai Do not push more commits. I took over and finalized the PR and I also rewrote some hard-to-read sections of the existing docs.

vectors Array(Float*),
INDEX <index_name> vectors TYPE vector_similarity(<type>, <distance_function>, <dimensions>) [GRANULARITY <N>]
[...],
vectors Array([Float64|Float32|BFloat32]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BFloat32 is not a ClickHouse type. The surrounding text in this guide still documents the supported vector-column types as Array(Float64), Array(Float32), and Array(BFloat16), so this example now points readers at a nonexistent schema. Please switch this placeholder to BFloat16.

CREATE TABLE tab
(
id Int32,
vec Array(BFloat16)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changing this example to Array(BFloat16) also requires regenerating the captured result blocks. Values like 2.1 and 2.2 round to 2.09375 and 2.203125 in BFloat16, so the current responses still show the old Float32 output. The same stale output is repeated again in the later approximate-search example.

1. │ Expression (Project names) │
2. │ Header: id Int32 │
3. │ Limit (preliminary LIMIT (without OFFSET)) │
4. │ Header: L2Distance(__table1.vec, _CAST([0., 2.]_Array(BFloat16), 'Array(BFloat16)'_String)) BFloat16 │

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This EXPLAIN block no longer matches the implementation. L2Distance over Array(BFloat16) widens to Float32, so the Header and _distance rows here should still be Float32, not BFloat16. As written, the guide claims an EXPLAIN result users cannot reproduce.

@rschu1ze

Copy link
Copy Markdown
Member

@Blargian The docs check fails and I'm not able to decipher what the error message means:

yarn run v1.22.22
$ bash ./scripts/build.sh
Building default Docusaurus (English)
Loaded 4 frontmatter exception(s)
[INFO] [en] Creating an optimized production build...
Loaded 4 frontmatter exception(s)
Processed code imports in: docs/use-cases/observability/clickstack/deployment/_snippets/_config_example_otel.md
Processed code imports in: docs/use-cases/observability/clickstack/ingesting-data/collector.md
Browserslist: browsers data (caniuse-lite) is 18 months old. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
[ERROR] Client bundle compiled with errors therefore further build is impossible.
× Module build failed:
  ╰─▶   × Error: MDX compilation failed for file "/opt/clickhouse-docs/docs/engines/table-engines/mergetree-family/annindexes.md"
        │ Cause: Could not parse import/exports with acorn
        │ Details:
        │ {
        │   "cause": {
        │     "pos": 39813,
        │     "loc": {
        │       "line": 643,
        │       "column": 7
        │     },
        │     "raisedAt": 51
        │   },
        │   "column": 8,
        │   "message": "Could not parse import/exports with acorn",
        │   "line": 643,
        │   "name": "643:8",
        │   "place": {
        │     "line": 643,
        │     "column": 8,
        │     "offset": 39813
        │   },
        │   "reason": "Could not parse import/exports with acorn",
        │   "ruleId": "acorn",
        │   "source": "micromark-extension-mdxjs-esm",
        │   "url": "https://github.com/micromark/micromark-extension-mdxjs-esm#could-not-parse-importexports-with-acorn"
        │ }
        │
        │     at compileToJSX (/opt/clickhouse-docs/node_modules/@docusaurus/mdx-loader/lib/utils.js:93:15)
        │     at async loadMDX (/opt/clickhouse-docs/node_modules/@docusaurus/mdx-loader/lib/loader.js:22:20)
        │     at async Object.mdxLoader (/opt/clickhouse-docs/node_modules/@docusaurus/mdx-loader/lib/loader.js:156:24)
Build failed with status 1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Do you have an idea?

@Blargian

Blargian commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

docs/en/engines/table-engines/mergetree-family/annindexes.md

@rschu1ze it's because of this: https://github.com/ClickHouse/ClickHouse/pull/111156/changes/BASE..063b7f93c71db27aa34964d28e457d3cf9126aa2#r3620883102 the import is already defined at the top of the page. Pushed a fix.


The points in the vector space are stored in a column `vectors` of array type, e.g. [Array(Float64)](../../../sql-reference/data-types/array.md), [Array(Float32)](../../../sql-reference/data-types/array.md), or [Array(BFloat16)](../../../sql-reference/data-types/array.md).
The points in the vector space are stored in a column `vectors` of type [Array(Float64)](../../../sql-reference/data-types/array.md), [Array(Float32)](../../../sql-reference/data-types/array.md), or [Array(BFloat16)](../../../sql-reference/data-types/array.md).
For practical usage, we generally recommend using [BFloat16](../../../sql-reference/data-types/float.md) arrays.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change only updates the legacy Docusaurus source file, but the Mintlify page for the same slug is still the old Float32 version. docs/_migration/slug-map.csv:365 maps /engines/table-engines/mergetree-family/annindexes to docs/reference/engines/table-engines/mergetree-family/annindexes.mdx, and docs/reference/navigation.json:362 still serves that Mintlify page from the reference nav.

As a result, this PR leaves the two documentation trees contradicting each other: the new docs/en/.../annindexes.md recommends Array(BFloat16), while docs/reference/.../annindexes.mdx still recommends Array(Float32) and keeps the old examples. Please port the same edits to the Mintlify page in this PR so the reference docs do not stay stale.

@rschu1ze
rschu1ze added this pull request to the merge queue Jul 21, 2026
Merged via the queue into ClickHouse:master with commit 5f88640 Jul 21, 2026
178 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 21, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ddings-bfloat16

Docs: use Array(BFloat16) for vector embeddings in vector-search examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-documentation Documentation PRs for the specific code PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants