Skip to content

T3214 mappings exclude vectors#4758

Merged
andrew-nowak merged 9 commits into
guardian:mainfrom
bbc:t3214-mappings-exclude-vectors
Jun 12, 2026
Merged

T3214 mappings exclude vectors#4758
andrew-nowak merged 9 commits into
guardian:mainfrom
bbc:t3214-mappings-exclude-vectors

Conversation

@AndyKilmory

@AndyKilmory AndyKilmory commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

What does this change?

This adds a new configuration parameter - es.includeDenseVectorMappings - which can take values 'true' or 'false' (default value if not included = true) and will control whether the DenseVectorField used for adding embedding vector data to the Elasticsearch/Opensearch index will be included or not. False will exclude the mapping structures from the index and so allow continued use with Opensearch (post fork) indexes without modification until a longer term solution can be established.

The config parameter should be added to Thrall and Media-Api services to fully resolve all the issues.

In addition the parameter has been used to add in checks to the knnSearch and hybridSearch to return empty results sets when the embedding data has been excluded from the index.

How should a reviewer test this change?

Ensure that the ES/Opensearch index will operate as expected and the api and thrall services run as expected with both settings for the parameter - true and false.

Who should look at this?

Tested? Documented?

  • locally by committer
  • locally by Guardian reviewer
  • on the Guardian's TEST environment
  • relevant documentation added or amended (if needed)

@AndyKilmory AndyKilmory marked this pull request as ready for review June 9, 2026 10:13
@AndyKilmory AndyKilmory requested a review from a team as a code owner June 9, 2026 10:13
Comment thread dev/script/generate-config/service-config.js
(implicit ex: ExecutionContext, logMarker: LogMarker): Future[SearchResults] = {
if (!includeDenseVectorMappings) {
logger.warn(logMarker, "knnSearch called but includeDenseVectorMappings=false, returning empty results")
return Future.successful(SearchResults(Nil, total = 0, extraCounts = None))

@Conalb97 Conalb97 Jun 9, 2026

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.

I think return would be redundant here since in Scala the last expression in a method is implicitly returned, so:

if (!includeDenseVectorMappings) {
  logger.warn(...)
  Future.successful(SearchResults(Nil, total = 0, extraCounts = None))
}

Should be fine

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

return removed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is usually true, but in this case this line is not the last expression in the method, so it is not implicitly returned. Either the remaining expressions in the method need to be inside an else block, or we need to use the return keyword (in general I'd recommend avoiding the return keyword as it does not always behave as you might expect, see https://tpolecat.github.io/2014/05/09/return.html. In this case I think it'd technically be fine here, but it's usually better to avoid it out of principle, to avoid needing to think too hard about whether it will definitely do what you want it to)

Comment thread media-api/app/lib/elasticsearch/ElasticSearch.scala Outdated
Comment thread thrall/app/lib/elasticsearch/ElasticSearch.scala Outdated
@AndyKilmory

Copy link
Copy Markdown
Collaborator Author

Have added else clauses to make early return pattern explicit and also resolved conflicts

@andrew-nowak andrew-nowak added the maintenance Departmental tracking: maintenance work, not a fix or a feature label Jun 12, 2026
@gu-prout

gu-prout Bot commented Jun 12, 2026

Copy link
Copy Markdown

Seen on auth, metadata-editor, cropper, collections, kahuna (created by @AndyKilmory and merged by @andrew-nowak 9 minutes and 44 seconds ago) Please check your changes!

@gu-prout

gu-prout Bot commented Jun 12, 2026

Copy link
Copy Markdown

Seen on thrall, leases, usage (created by @AndyKilmory and merged by @andrew-nowak 9 minutes and 51 seconds ago) Please check your changes!

@gu-prout

gu-prout Bot commented Jun 12, 2026

Copy link
Copy Markdown

Seen on media-api (created by @AndyKilmory and merged by @andrew-nowak 9 minutes and 55 seconds ago) Please check your changes!

@gu-prout

gu-prout Bot commented Jun 12, 2026

Copy link
Copy Markdown

Seen on image-loader (created by @AndyKilmory and merged by @andrew-nowak 10 minutes ago) Please check your changes!

@gu-prout

gu-prout Bot commented Jun 12, 2026

Copy link
Copy Markdown

Seen on image-loader (created by @AndyKilmory and merged by @andrew-nowak 10 minutes and 1 second ago) Please check your changes!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants