Closed Tejaswgupta closed 10 months ago
🤖
Hello,
The error message you're seeing is due to the search
method in the DocstoreExplorer
class requiring a search_type
argument that is not being provided.
In your code, you're initializing the Search
tool with the docstore.search
function:
Tool(
name="Search",
func=docstore.search,
description="useful for when you need to ask with search",
),
However, the search
method in the DocstoreExplorer
class requires two arguments: term
and search_type
. You're providing the term
argument when you call react.run('Punishment for drinking and driving')
, but the search_type
argument is missing.
To resolve this issue, you need to ensure that the search_type
argument is provided when the search
method is called. This could be done by modifying the Tool
object to accept arguments, or by providing a default search_type
in the search
method definition.
Please note that the exact solution would depend on the rest of your code and how the Tool
object is used. If you need further assistance, please provide more details about your implementation and how you're using the Tool
object.
Best, Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
@dosu-bot
Looking at libs/langchain/langchain/agents/react/base.py
DocstoreExplorer doesn't have a requirement for search_type
.
class DocstoreExplorer:
"""Class to assist with exploration of a document store."""
def __init__(self, docstore: Docstore):
"""Initialize with a docstore, and set initial document to None."""
self.docstore = docstore
self.document: Optional[Document] = None
self.lookup_str = ""
self.lookup_index = 0
def search(self, term: str) -> str:
"""Search for a term in the docstore, and if found save."""
result = self.docstore.search(term)
if isinstance(result, Document):
self.document = result
return self._summary
else:
self.document = None
return result
def lookup(self, term: str) -> str:
"""Lookup a term in document (if saved)."""
if self.document is None:
raise ValueError("Cannot lookup without a successful search first")
if term.lower() != self.lookup_str:
self.lookup_str = term.lower()
self.lookup_index = 0
else:
self.lookup_index += 1
lookups = [p for p in self._paragraphs if self.lookup_str in p.lower()]
if len(lookups) == 0:
return "No Results"
elif self.lookup_index >= len(lookups):
return "No More Results"
else:
result_prefix = f"(Result {self.lookup_index + 1}/{len(lookups)})"
return f"{result_prefix} {lookups[self.lookup_index]}"
@property
def _summary(self) -> str:
return self._paragraphs[0]
@property
def _paragraphs(self) -> List[str]:
if self.document is None:
raise ValueError("Cannot get paragraphs without a document")
return self.document.page_content.split("\n\n")
🤖
Hello,
Thank you for reaching out and providing a detailed description of your issue. The error message you're seeing, TypeError: search() missing 1 required positional argument: 'search_type'
, suggests that the search()
function is expecting an argument named search_type
that isn't being provided.
However, based on the code you've shared, it seems that the search()
function in the DocstoreExplorer
class doesn't require a search_type
argument. It only requires a term
argument. This suggests that the error might be originating from somewhere else in your code.
The search_type
argument is used in the similarity_search_with_score
and _raw_similarity_search_with_score
methods of the OpenSearchVectorSearch
class, not in the DocstoreExplorer
class. It's used to specify the type of search to be performed and can take one of three values: "approximate_search", "script_scoring", or "painless_scripting".
I recommend checking the rest of your code to ensure that the search()
function is being called correctly. If you're using the OpenSearchVectorSearch
class or a similar class that requires a search_type
argument, make sure you're providing that argument when calling the search()
function.
If you're still encountering this issue after checking your code, could you please provide more information about the context in which you're using the DocstoreExplorer
class? Specifically, it would be helpful to know more about the vectordb
object that you're passing to the DocstoreExplorer
constructor, as well as any other parts of your code that interact with the DocstoreExplorer
instance.
I hope this helps, and I look forward to your response.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Hi, @Tejaswgupta
I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you reported a TypeError in the search method of the DocstoreExplorer, and there was a discussion about the potential cause of the error. However, the issue remains unresolved.
Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, kindly let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and cooperation.
System Info
Name: langchain Version: 0.0.300 Summary: Building applications with LLMs through composability Home-page: https://github.com/langchain-ai/langchain Author: None Author-email: None License: MIT Location: /anaconda/envs/azureml_py38/lib/python3.8/site-packages Requires: requests, jsonpatch, dataclasses-json, numpy, tenacity, numexpr, aiohttp, langsmith, anyio, SQLAlchemy, pydantic, async-timeout, PyYAML Required-by: llama-index
Who can help?
No response
Information
Related Components
Reproduction
Error:
Expected behavior
Should successfully execute.