Skip to content
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

[Search][Playground] Support Multiple Context Fields #210703

Merged

Conversation

TattdCodeMonkey
Copy link
Contributor

@TattdCodeMonkey TattdCodeMonkey commented Feb 11, 2025

Summary

This PR updates the search playground to allow selecting > 1 context fields to be included in context documents for the LLM.

Screenshots

image

Context Fields Updated to ComboBox:
image

Checklist

@TattdCodeMonkey TattdCodeMonkey added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:Search v9.1.0 labels Feb 11, 2025
@TattdCodeMonkey TattdCodeMonkey requested review from a team as code owners February 11, 2025 21:56
@TattdCodeMonkey TattdCodeMonkey force-pushed the playground/multi-context-fields branch 2 times, most recently from c71a1fb to 9bbdd10 Compare February 11, 2025 21:59
Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

x-pack/test/functional/config.base.js changes LGTM

Copy link
Contributor

@Samiul-TheSoccerFan Samiul-TheSoccerFan left a comment

Choose a reason for hiding this comment

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

LGTM, left some comments. It might be worth having @yansavitski take a look as well.

};
}, [indexFields.source_fields, selectedContextFields]);
const onSelectFields = useCallback(
(updatedSelectedOptions: Array<EuiComboBoxOptionOption<unknown>>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we avoid defining unknown and any as a type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should avoid any, uknown is perfectly fine.

Using unknown TS will make you do type checks to validate what the type is. But in this case thats the option data type and what we need to access is for the EuiComboBoxOptionOption. So the option type is not needed in this callback currently.

size="s"
/>
)}
<ContextFieldsSelect
Copy link
Contributor

Choose a reason for hiding this comment

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

neat!

@@ -38,7 +38,7 @@ describe('conversational chain', () => {
expectedTokens?: any;
expectedErrorMessage?: string;
expectedSearchRequest?: any;
contentField?: Record<string, string>;
contentField?: Record<string, string | string[]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

may be replace this with ElasticsearchRetrieverContentField?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ElasticsearchRetrieverContentField is string | Record<string, string | string[]> which would then require this filed to handle contentField being a string. Which it never is. So it would just unnecessarily complicate this code IMO.

@TattdCodeMonkey
Copy link
Contributor Author

@Samiul-TheSoccerFan FYI this PR is 90% there but I still have to update the UI to select all the context fields by default. Which is what I'll be working on today.

(hit: SearchHit): Document => {
let pageContent: string = '';
const makePageContentForField = (field: string) =>
`${field}: ${getValueForSelectedField(hit, field)}`;
Copy link
Member

Choose a reason for hiding this comment

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

update this function to check if contentField has a field value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

@joemcelroy
Copy link
Member

works well! tested with a few scenarios. The only thing left is updating the view code example to include multiple context fields.

Copy link
Contributor

@yansavitski yansavitski left a comment

Choose a reason for hiding this comment

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

LGTM

@TattdCodeMonkey
Copy link
Contributor Author

TattdCodeMonkey commented Feb 14, 2025

@joemcelroy can we update the python code to support multiple context fields? looking at the python code it looks like it only support str or Mapping[str, str] and not Mapping[str, str[]] which is what we would need right?

Or does that just mean we need to show a custom document mapper if there is multiple context fields?

I did update the vanilla python example to support multiple context fields, but I haven't had a chance to test that code yet. So i'll need to do that before we merge these changes.

@TattdCodeMonkey TattdCodeMonkey force-pushed the playground/multi-context-fields branch from ed717eb to 96f1989 Compare February 14, 2025 20:01
@joemcelroy
Copy link
Member

@joemcelroy can we update the python code to support multiple context fields? looking at the python code it looks like it only support str or Mapping[str, str] and not Mapping[str, str[]] which is what we would need right?

Or does that just mean we need to show a custom document mapper if there is multiple context fields?

Yes, for LangChain code lets have a custom document mapper if theres multiple context fields. We can consider in future to update the LangChain retriever to support multiple context fields.

@TattdCodeMonkey TattdCodeMonkey force-pushed the playground/multi-context-fields branch from dd48e86 to 7d618de Compare February 18, 2025 22:01
@TattdCodeMonkey
Copy link
Contributor Author

TattdCodeMonkey commented Feb 20, 2025

@joemcelroy this is updated to use a custom document mapper for langchain retriever if you have >1 context field selected. I tested both scenarios locally and everything should be good and functional.

I did update the question in the lang chain example to be more generic and try and encourage its replacement based on actually user data "What is it you want to ask the LLM?"

If you have time give it another 👀

Copy link
Member

@joemcelroy joemcelroy left a comment

Choose a reason for hiding this comment

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

This is great! Thank you.

@TattdCodeMonkey
Copy link
Contributor Author

@elasticmachine merge upstream

@TattdCodeMonkey TattdCodeMonkey enabled auto-merge (squash) February 21, 2025 16:46
@TattdCodeMonkey TattdCodeMonkey merged commit ef2ec69 into elastic:main Feb 21, 2025
9 checks passed
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #46 / visualize app annotation listing page search "after each" hook for "filters by tag"
  • [job] [logs] FTR Configs #46 / visualize app annotation listing page search by tag filters by tag

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
searchPlayground 292 293 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
searchPlayground 186.2KB 187.6KB +1.3KB

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Search v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants