serpapi prevent exact-match google search
I just encountered this error similar with the issue #323:
No good Google Search Results was found
after the investigation, I found sometimes the llm model(e.g. mistral in ollama) will return Action Input value surrounded by double quotes
which will became a exact-match behavior and usually find nothing:
# this is ok, just get name from search engine and continue the following steps
Action: GoogleSearch
Action Input: Oliva Wilde boyfriend age
# error: No good Google Search Results was found
Action: GoogleSearch
Action Input: "Oliva Wilde boyfriend age"
with quotes, the actual query string in serpapi became:
"q": "\"Oliva Wilde boyfriend age\"",
and this also appeared in issue #323
# python version
"q": "current weather in Ramnicu Valcea, Romania",
# langchaingo
"q": ""current+weather+in+Ramnicu+Valcea,+Romania"",
another change is the description of this tool: I compared serpapi tool description in langchain python and langchaingo, I tried several times, In my use experience, I feel the python version would worked better, but I'm not the expert in prompt engineering , so if this should not be changed, I'm going to delete this modification.
# langchaingo currently use:
`
"A wrapper around Google Search. "
"Useful for when you need to answer questions about current events. "
"Always one of the first options when you need to find information on internet"
"Input should be a search query."
`
# langchain python serpapi:
"A search engine. Useful for when you need to answer questions about current events. Input should be a search query."
PR Checklist
- [x] Read the Contributing documentation.
- [x] Read the Code of conduct documentation.
- [x] Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as
memory: add interfaces for X, Yorutil: add whizzbang helpers). - [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
Fixes #123). - [x] Describes the source of new concepts.
- [x] References existing implementations as appropriate.
- [x] Contains test coverage for new functions.
- [x] Passes all
golangci-lintchecks.
I like the prompt adjustment but I'm less sure about the quote stripping -- putting this in prevents callers specifying exact-search style queries, right?
Yeah, to simulate this problem, I put a fake name for serpapi search:
"search_parameters":{
"engine":"google",
"q":"\"Bdfese Eeeitfa boyfriend\"",
},
the result would be:
then return error: No good Google Search Results was found
if the we remove quotes, search engine will result some irrelevant information to llm then llm could evaluate that information this is finally result in my case:
answer: Unfortunately, there isn't sufficient information available to determine Bdfese Eeeitfa's boyfriend or their current age, so we cannot compute their age raised to the 0.23 power.
I think it's more appropriate for the caller to simply do a strings.Trim() call head of calling search.
I think it's more appropriate for the caller to simply do a strings.Trim() call head of calling search.
Yes, that’s more preferable, I merge latest main branch and updated it.