Skip to content

Conversation

@markjhoy
Copy link
Contributor

@markjhoy markjhoy commented Dec 5, 2025

(DRAFT - needs tests and docs)

Adds query_vector_builder support to the diversify retriever

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

🔍 Preview links for changed docs

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 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?

@markjhoy
Copy link
Contributor Author

markjhoy commented Dec 5, 2025

FYI - I added a new YAML test at x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_diversifty_retriever.yml to verify the use of the query_vector_builder in a real-world scenario (as it needs inference). I'll reuse this later in additional features for the retriever.

@markjhoy markjhoy marked this pull request as ready for review December 5, 2025 20:35
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Dec 5, 2025
@markjhoy markjhoy added Team:SearchOrg Meta label for the Search Org (Enterprise Search) and removed needs:triage Requires assignment of a team area label labels Dec 5, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@markjhoy markjhoy added the :SearchOrg/Relevance Label for the Search (solution/org) Relevance team label Dec 5, 2025
@markjhoy markjhoy requested a review from a team December 5, 2025 20:37
@elasticsearchmachine elasticsearchmachine added the Team:Search - Relevance The Search organization Search Relevance team label Dec 5, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/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.

Nice start!

Must be either an array of floats or a hex-encoded byte vector.
If you provide a `query_vector`, you cannot also provide a `query_vector_builder`.

`query_vector_builder`
Copy link
Member

Choose a reason for hiding this comment

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

Please don't throw 🍅 at me 🙈

I think we should verify that we want the same query_vector_builder API here. There's some legacy API crust, for example the API asks for a model_id etc. and there's opportunity to modernize it with inference_id. This would be more work, though, so I'm not raising it as a blocker to the PR more as a discussion if that's something we want to bite off or if this is OK.

If we decide to go forward with query_vector_builder, perhaps not for this PR but the docs could use a bit of work here to define allowed parameters, and have something directly linkable.

Copy link
Contributor Author

@markjhoy markjhoy Dec 5, 2025

Choose a reason for hiding this comment

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

I agree with what you're saying - but I think it's a larger, and more discrete PR (as it also touches other users of the QueryVectorBuilder). The docs however are probably a good idea.

&& this.diversificationField.equals(other.diversificationField)
&& Objects.equals(this.lambda, other.lambda)
&& Objects.equals(this.queryVector, other.queryVector);
&& ((queryVector == null && other.queryVector == null)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't Objects.equals take care of the null checks already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily in this case, as the query_vector is now a supplier, so we need to make sure the suppled value is equal, but if the supplier is null it'll throw when the .get() is issued.

Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Typo in filename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦

@@ -0,0 +1,127 @@
setup:
- requires:
cluster_features: [ "retriever.result_diversification_mmr" ]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can re-use the cluster feature here, we need a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll double check. This was a carry over from the original YAML tests for the retriever, but may not be needed here...

retriever:
knn:
field: "textvector"
query_vector: [ 0.5, 0.2, 0.4, 0.4 ]
Copy link
Member

Choose a reason for hiding this comment

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

This is using a query vector, not a query vector builder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's testing the query vector builder in the diversify retriever only - the inner retriever is irrelevant. But, I can change it.

- length: { hits.hits: 3 }

---
"Validate query_vector or query_vector_builder but not both":
Copy link
Member

Choose a reason for hiding this comment

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

Can we also validate an incorrectly formatted query vector builder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be caught by the parser, but to be sure, I'll add a test in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search - Relevance The Search organization Search Relevance team Team:SearchOrg Meta label for the Search Org (Enterprise Search) v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants