Skip to content

(EAI-990): Refactor search as a tool #705

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

Merged
merged 30 commits into from
Jun 4, 2025
Merged

Conversation

mongodben
Copy link
Collaborator

@mongodben mongodben commented May 9, 2025

Jira: https://jira.mongodb.org/browse/EAI-990

Changes

  • Refactor chatbot to use tool calling for search
    • general generateResponseWithSearchTool() to be used with arbitrary search tool in mongodb-chatbot-server
  • Add our implementation of search as tool to chatbot-server-mongodb-public
    • as a result of this change, can remove 2 LLM preprocessors, the step back query generator, and also the metadata extractor
  • Upgrade to use GPT-4.1 in chatbot
  • Fix broken tests in branch

Notes

@mongodben mongodben changed the title Eai 990: functional tool calling Eai 990: tool calling search May 9, 2025
@mongodben mongodben changed the title Eai 990: tool calling search (EAI-990): Refactor search as a tool May 27, 2025
@mongodben mongodben marked this pull request as ready for review May 27, 2025 20:52
Copy link
Collaborator

@nlarew nlarew left a comment

Choose a reason for hiding this comment

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

LGTM - lots going on in this one so generally trusting you that it works as expected. Proof is in the pudding!

Comment on lines 69 to 74
const result = makeMongoDbReferences(
chunks.map((c) => ({
...c,
title: c.metadata?.pageTitle,
}))
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to modify the chunks here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

umm we probably dont. esp based on what the change is doing. will poke at and either 1) report back on why we do, or 2) revert

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

update: reverting. no change in behavior

'If the user query is already a "good" search query, do not modify it.',
'For one word queries like "or", "and", "exists", if the query corresponds to a MongoDB operation, transform it into a fully formed question. Ex: If the user query is "or", transform it into "what is the $or operator in MongoDB?".',
"You should also transform the user query into a fully formed question, if relevant.",
`Only generate ONE ${SEARCH_TOOL_NAME} tool call per user message unless there are clearly multiple distinct queries needed to answer the user query.`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume we handle the multiple tool call case in regards to reference links?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea, it all appends to an array of references, which is streamed after the text generation

@@ -12,6 +12,7 @@ export function extractTracingData(
messages: Message[],
assistantMessageId: ObjectId
) {
// FIXME: this is throwing after the generation is complete. don't forget to fix before merge of EAI-990
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this and other TODO in this file fixed in another PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in other PR! #759

dataStreamer,
});

// TODO: verify dataStreamer was called
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need todo still or covered in another PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm not sure, will add here just in case. easy fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

was added in later PR but added here as well, just in case

mongodben and others added 3 commits June 4, 2025 08:48
@mongodben mongodben merged commit 50d3f44 into retrieval_tool_call Jun 4, 2025
1 check was pending
@mongodben mongodben deleted the EAI-990 branch June 4, 2025 13:13
mongodben added a commit that referenced this pull request Jun 11, 2025
* (EAI-988): Refactor `GenerateResponse` for tool call support  (#687)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* (EAI-989): Refactor verified answers to wrap `GenerateResponse` (#688)

verified answer generate response

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* handle streaming

* separate generateresponse

* typo fix

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-990): Refactor search as a tool  (#705)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* update default ref links

* fix broken tests

* Apply suggestions from code review

Co-authored-by: Nick Larew <nick.larew@mongodb.com>

* revert default reference links

* adding missing test

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>
Co-authored-by: Nick Larew <nick.larew@mongodb.com>

* (EAI-992): Remove `ChatLlm` (#751)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* remove ChatLlm

* lite fixes

* Remove stub

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-993): deprecate framework (#752)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* deprecation

* build out docs following last week convo

* clean up spec + contact

* fix merge funk

* docs updates

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-1071): Fix broken Atlas OpenAPI ingest (#765)

* update to fix broken test

* Update packages/ingest-mongodb-public/src/sources/snooty/snootyAstToOpenApiSpec.ts

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-995): add guardrail (#755)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* update default ref links

* fix broken tests

* input guardrail refactor

* guardrail works well

* simpler validity metric

* add guardrail to server

* add next step todo

* llm refusal msg

* remove TODO comment

* merge fix

* fix unnec changes

* NL feedback

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* fix type in text

* (EAI-991 & EAI-1050): Evaluate and clean up retrieval as a tool (#757)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* update default ref links

* fix broken tests

* input guardrail refactor

* guardrail works well

* simpler validity metric

* add guardrail to server

* add next step todo

* llm refusal msg

* remove TODO comment

* evals on new architecture

* Get urls in a way that supports verified answers

* dont eval on retrieved elems if no context

* Cleaner handling

* update trace handling

* update trace handling

* undo git funk

* handle undefined case

* Fix tracing test

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* remove console logs + redunancies

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>
Co-authored-by: Nick Larew <nick.larew@mongodb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants