Skip to content

ES|QL - Completion command #124405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 of 9 tasks
afoucret opened this issue Mar 8, 2025 · 8 comments
Open
4 of 9 tasks

ES|QL - Completion command #124405

afoucret opened this issue Mar 8, 2025 · 8 comments
Assignees
Labels
ES|QL-ui Impacts ES|QL UI >feature Meta priority:normal A label for assessing bug priority to be used by ES engineers :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.0.0

Comments

@afoucret
Copy link
Contributor

afoucret commented Mar 8, 2025

Tracked in #123043

The completion command will be used to execute a completion through an LLM using ES}QL.

Command grammar

| COMPLETION <prompt> WITH <inferenceId> (AS <targetField>)

where

param required description
prompt required Provides the prompt to be executed for the row.The prompt can be built from a mix a constant and field values.
inferenceId required Endpoint used to do the completion(can be optional when we will have a default LLM in EIS).
targetField optionaldefault: completion Name of the result column.

Usage example:

Row by row

FROM search-movies
| WHERE match(plot, "Gandalf the grey")
| EVAL prompt= CONCAT(
      "Extract movie genre:\n",
       "<title>", title, "</title>",
       "<actors>", MV_CONCAT(actors, ","), "</actors">,
       "<plot>", plot, "</plot"
    )
| COMPLETION prompt WITH "openai-completion" AS genre
| DROP prompt

Aggregated rows:

FROM business-news
| WHERE industry:technology AND date:today
| EVAL company_data = CONCAT(
        "<title>", title, "</title>",
        "<summary>", summary, "</summary">
        "<article>", title, "</article"
    )
| STATS company_data = VALUES(company_data) BY company
| EVAL prompt=CONCAT(
        Summarize important news for the copmany\n",
        "<company>", company, "</company>\n",
        MV_CONCAT(company_data, "\n")
    )
| COMPLETION prompt WITH "openai-completion" AS company_news

Development

@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Mar 8, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Mar 8, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Mar 8, 2025
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label and removed Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Mar 8, 2025
@afoucret afoucret added >feature Meta :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.0.0 and removed needs:triage Requires assignment of a team area label labels Mar 8, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@afoucret afoucret added the priority:normal A label for assessing bug priority to be used by ES engineers label Mar 8, 2025
@ioanatia ioanatia changed the title ES}QL - Completion command ES|QL - Completion command Mar 11, 2025
@Mikaayenson
Copy link

Mikaayenson commented Mar 14, 2025

👋 This is great to see. Aligns really well with what we're proposing here

@afoucret
Copy link
Contributor Author

@Mikaayenson Also, the implementation will be using the ES|QL inference infrastructure we have created for the Rerank command command which should be merged very soon as a tech preview (see PR here #123074).

@ioanatia
Copy link
Contributor

I have to say I much prefer the original COMPLETION proposal that was working row by row:

FROM movies
  | WHERE title:"star wars"
  | COMPLETION "Summarize the provided document" USING title, overview=SUBSTRING(overview, 0, 100), actors WITH "completionInferenceId" AS summary

If we want to use chat completion on aggregate values, we should just add that as an option to COMPLETION.
However I don't see this as an immediate requirement for COMPLETION.

@Mikaayenson
Copy link

@afoucret / @ioanatia thanks for the conversation today! I've gone ahead and linked this PR to the RFC

This proposal aligns well with the upcoming COMPLETION ESQL command that has different syntax but generally meets the needs, with a few caveats that will be sidelined for now.

  • Referencing the modelID within the query adds validation complications for prebuilt rules. Ideally this will be optional in the future. Elastic Security will ship an always-on prebuilt llm model/option. It would be great if this could be leveraged to also ease the query development/management. (future goal)
  • COMPLETIONS return text. Ideally we will be able to specify structured return types like DOUBLE so that we do not have to introduce additional steps to obtain a probability score.
  • One other use case to mention here is the ability to pseudo perform entity resolution based on the COMPLETION results. (e.g. COMPLETION "These users are the same user." USING proofpoint.user_name, ,endpoint.user_name WITH "completionInferenceId" AS entity_resolution_score)

@ioanatia ioanatia added the ES|QL-ui Impacts ES|QL UI label Mar 19, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/kibana-esql (ES|QL-ui)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES|QL-ui Impacts ES|QL UI >feature Meta priority:normal A label for assessing bug priority to be used by ES engineers :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.0.0
Projects
None yet
Development

No branches or pull requests

4 participants