DocstoreExplorer Class — langchain Architecture
Architecture documentation for the DocstoreExplorer class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a63b0fef_9f28_1339_c784_3f96b497636a["DocstoreExplorer"] 935e1032_d88a_f226_7789_5aacc43bb0c8["Document"] a63b0fef_9f28_1339_c784_3f96b497636a -->|extends| 935e1032_d88a_f226_7789_5aacc43bb0c8 9ccefa56_209b_c990_304c_d902563c789e["base.py"] a63b0fef_9f28_1339_c784_3f96b497636a -->|defined in| 9ccefa56_209b_c990_304c_d902563c789e 00a7c695_d7b4_3d1a_123d_baa7e8c87927["__init__()"] a63b0fef_9f28_1339_c784_3f96b497636a -->|method| 00a7c695_d7b4_3d1a_123d_baa7e8c87927 0302beb1_1ddf_3755_f461_54162de12e81["search()"] a63b0fef_9f28_1339_c784_3f96b497636a -->|method| 0302beb1_1ddf_3755_f461_54162de12e81 02a2958f_7374_1f5e_0897_f932eb954395["lookup()"] a63b0fef_9f28_1339_c784_3f96b497636a -->|method| 02a2958f_7374_1f5e_0897_f932eb954395 c3532df5_6e84_5467_2953_e60282892892["_summary()"] a63b0fef_9f28_1339_c784_3f96b497636a -->|method| c3532df5_6e84_5467_2953_e60282892892 7d5a2bdc_a9ca_974a_8b22_ec1d405f35f4["_paragraphs()"] a63b0fef_9f28_1339_c784_3f96b497636a -->|method| 7d5a2bdc_a9ca_974a_8b22_ec1d405f35f4
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/react/base.py lines 89–135
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: Document | None = 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
self.document = None
return result
def lookup(self, term: str) -> str:
"""Lookup a term in document (if saved)."""
if self.document is None:
msg = "Cannot lookup without a successful search first"
raise ValueError(msg)
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"
if self.lookup_index >= len(lookups):
return "No More Results"
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:
msg = "Cannot get paragraphs without a document"
raise ValueError(msg)
return self.document.page_content.split("\n\n")
Extends
Source
Frequently Asked Questions
What is the DocstoreExplorer class?
DocstoreExplorer is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/react/base.py.
Where is DocstoreExplorer defined?
DocstoreExplorer is defined in libs/langchain/langchain_classic/agents/react/base.py at line 89.
What does DocstoreExplorer extend?
DocstoreExplorer extends Document.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free