Skip to content

Conversation

@carlosdelest
Copy link
Member

@carlosdelest carlosdelest commented Sep 2, 2025

Adds a TO_DENSE_VECTOR conversion function to convert to dense_vectors:

  • Multivalued numbers: [0.1, 0.2, 0.3], [1, 2, 3]
  • Hex strings: "532af3e"

Also, performs automatic conversion of vector values for VectorFunction instances on the Analyzer:

FROM test
| WHERE knn(vector_field, [0, 1, 2])

or

FROM test
| EVAL s = v_hamming("asdf2342", [0, 1, 2])

The Analyzer will convert automatically keyword fields via castStringLiteral, and add a TO_DENSE_VECTOR function for numeric values.

In order to use a reference attribute for a vector function, we need to use TO_DENSE_VECTOR explicitly, just like other types like IP:

FROM test
| EVAL query = TO_DENSE_VECTOR([1, 2, 3])
| WHERE knn(vector_field, query)

For now, hex strings gets translated to byte dense_vectors. We can create a follow up function TO_BIT_DENSE_VECTOR for using hex strings for bit vectors, or add an optional parameter to TO_DENSE_VECTOR.

@carlosdelest carlosdelest added >non-issue :Analytics/ES|QL AKA ESQL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.2.0 :Search Relevance/ES|QL Search functionality in ES|QL labels Sep 2, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

🔍 Preview links for changed docs

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

…vector-casting

# Conflicts:
#	x-pack/plugin/esql/qa/testFixtures/src/main/resources/knn-function.csv-spec
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java
@carlosdelest carlosdelest marked this pull request as ready for review September 4, 2025 13:41
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Sep 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Changes look good to me, nice work!

Copy link
Contributor

@tteofili tteofili left a comment

Choose a reason for hiding this comment

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

nice work Carlos, LGTM!

Source source,
@Param(
name = "field",
type = { "double", "long", "integer", "keyword" },
Copy link
Contributor

@afoucret afoucret Sep 9, 2025

Choose a reason for hiding this comment

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

Should we add text as well (if it is loaded from an ES text field)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would say no - it's ok to allow for hex string constants, but I don't think they should be analyzed in any way or retrieved from an analyzed field.

If any time this is needed, they can be converted via the ::keyword casting operator.

@carlosdelest carlosdelest added the test-release Trigger CI checks against release build label Sep 10, 2025
@carlosdelest carlosdelest enabled auto-merge (squash) September 10, 2025 10:27
@carlosdelest carlosdelest merged commit 5a0636a into elastic:main Sep 10, 2025
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >non-issue :Search Relevance/ES|QL Search functionality in ES|QL Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch test-release Trigger CI checks against release build v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants