langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
11.81k stars 1.98k forks source link

tavily search api is not reliable #5982

Open wulucxy opened 6 days ago

wulucxy commented 6 days ago

Checked other resources

Example Code

// ===tavily request=== { query: '"{\"input\":\"2023 NBA final winner\"}"', max_results: 1, api_key: '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' }

// ===tavily response=== { query: '"{\"input\":\"2023 NBA final winner\"}"', follow_up_questions: null, answer: null, images: null, results: [], response_time: 1.28 }

Error Message and Stack Trace (if applicable)

No response

Description

https://github.com/langchain-ai/langchainjs/blob/1fddf296f922dcaa362a90c8fe90b4bfd84b6c3e/libs/langchain-community/src/retrievers/tavily_search_api.ts#L97

the return of tavily search api always empty array

System Info

@langchain/community": "^0.2.13"

dosubot[bot] commented 6 days ago

@wulucxy Hello there! I'm here to assist you with any bugs, questions, or contributions. While you're waiting for a human maintainer, feel free to ask me anything.

The Tavily Search API returning an empty array in the results field could be due to several reasons:

  1. API Key Issue: Ensure that the API key is correctly set either through the environment variable TAVILY_API_KEY or passed directly in the apiKey field. If the API key is missing or incorrect, the request might not be processed correctly [1].

  2. Query Parameters: The parameters being sent in the request might not be yielding any results. Check the values for includeGeneratedAnswer, includeRawContent, includeImages, searchDepth, includeDomains, excludeDomains, and kwargs to ensure they are set correctly and are appropriate for the search query [1].

  3. API Response Handling: The code checks if json.results is an array. If the API response structure has changed or if there is an issue with the API itself, it might not return the expected results array [1].

  4. Recent Changes: There have been recent changes in the LangChain.js repository that affect the Tavily Search API retriever functionality. Ensure you are using the latest version and check for any migration warnings or updates [2][1].

  5. Error Codes or Messages: Specific error codes or messages returned by the Tavily Search API could indicate why the results field is empty. If the API request fails, it throws an error with the status code and the error message from the response [3].

  6. Default Parameter Values: The default values for parameters like includeGeneratedAnswer, includeRawContent, includeImages, searchDepth, includeDomains, and excludeDomains might affect the results. Ensure these are set appropriately for your query [1].

If the issue persists, consider enabling verbose logging or tracing to get more detailed information about the API requests and responses [4][5].

To continue talking to Dosu, mention @dosu.

jacoblee93 commented 6 days ago

Sorry you're running into this!

CC @rotemweiss57 for a look

rotemweiss57 commented 6 days ago

Hey @wulucxy! Please try to insert "2023 NBA final winner" instead of '"{\"input\":\"2023 NBA final winner\"}"' as it creates limitations. Hope it helps (:

wulucxy commented 5 days ago

@rotemweiss57 I don't think so.

{"input":"2023 NBA final winner"} was inferenced by model,as the schema defined by the tavily_search.

so you have to be think the implement of the tool

https://github.com/langchain-ai/langchainjs/blob/f5f2cf41c279a356cf702656a757413e1ae76732/libs/langchain-community/src/tools/tavily_search.ts#L45

wulucxy commented 5 days ago

@rotemweiss57 now I have been blocked here for a while, do you have any plan to improve this?

wulucxy commented 12 hours ago

@rotemweiss57 what's the progress here?