Home / Class/ ExaFindSimilarResults Class — langchain Architecture

ExaFindSimilarResults Class — langchain Architecture

Architecture documentation for the ExaFindSimilarResults class in tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2b330890_d049_cc63_2764_fc9bcce52bfb["ExaFindSimilarResults"]
  18e85ff8_9a5d_f800_f722_027398dc89e7["BaseTool"]
  2b330890_d049_cc63_2764_fc9bcce52bfb -->|extends| 18e85ff8_9a5d_f800_f722_027398dc89e7
  42caa1a3_7eac_fb42_5120_f01c6f7d463b["tools.py"]
  2b330890_d049_cc63_2764_fc9bcce52bfb -->|defined in| 42caa1a3_7eac_fb42_5120_f01c6f7d463b
  e12cb067_ba2c_ea6d_95a6_2c191c214849["validate_environment()"]
  2b330890_d049_cc63_2764_fc9bcce52bfb -->|method| e12cb067_ba2c_ea6d_95a6_2c191c214849
  e812ff94_a0ea_6298_d40c_2217749bbadd["_run()"]
  2b330890_d049_cc63_2764_fc9bcce52bfb -->|method| e812ff94_a0ea_6298_d40c_2217749bbadd

Relationship Graph

Source Code

libs/partners/exa/langchain_exa/tools.py lines 164–242

class ExaFindSimilarResults(BaseTool):  # type: ignore[override]
    """Tool that queries the Metaphor Search API and gets back json."""

    name: str = "exa_find_similar_results_json"
    description: str = (
        "A wrapper around Exa Find Similar. "
        "Input should be an Exa-optimized query. "
        "Output is a JSON array of the query results"
    )
    client: Exa = Field(default=None)  # type: ignore[assignment]
    exa_api_key: SecretStr = Field(default=SecretStr(""))
    exa_base_url: str | None = None

    @model_validator(mode="before")
    @classmethod
    def validate_environment(cls, values: dict) -> Any:
        """Validate the environment."""
        return initialize_client(values)

    def _run(
        self,
        url: str,
        num_results: int = 10,
        text_contents_options: TextContentsOptions  # noqa: FBT001
        | dict[str, Any]
        | bool
        | None = None,
        highlights: HighlightsContentsOptions | bool | None = None,  # noqa: FBT001
        include_domains: list[str] | None = None,
        exclude_domains: list[str] | None = None,
        start_crawl_date: str | None = None,
        end_crawl_date: str | None = None,
        start_published_date: str | None = None,
        end_published_date: str | None = None,
        exclude_source_domain: bool | None = None,  # noqa: FBT001
        category: str | None = None,
        livecrawl: Literal["always", "fallback", "never"] | None = None,
        summary: bool | dict[str, str] | None = None,  # noqa: FBT001
        run_manager: CallbackManagerForToolRun | None = None,
    ) -> list[dict] | str:
        """Use the tool.

        Args:
            url: The URL to find similar pages for.
            num_results: The number of search results to return (1 to 100). Default: 10
            text_contents_options: How to set the page content of the results. Can be True or a dict with options like max_characters.
            highlights: Whether to include highlights in the results.
            include_domains: A list of domains to include in the search.
            exclude_domains: A list of domains to exclude from the search.
            start_crawl_date: The start date for the crawl (in YYYY-MM-DD format).
            end_crawl_date: The end date for the crawl (in YYYY-MM-DD format).
            start_published_date: The start date for when the document was published (in YYYY-MM-DD format).
            end_published_date: The end date for when the document was published (in YYYY-MM-DD format).
            exclude_source_domain: If `True`, exclude pages from the same domain as the source URL.
            category: Filter for similar pages by category.
            livecrawl: Option to crawl live webpages if content is not in the index. Options: "always", "fallback", "never"
            summary: Whether to include a summary of the content. Can be a boolean or a dict with a custom query.
            run_manager: The run manager for callbacks.

        """  # noqa: E501
        try:
            return self.client.find_similar_and_contents(
                url,
                num_results=num_results,
                text=text_contents_options,
                highlights=highlights,
                include_domains=include_domains,
                exclude_domains=exclude_domains,
                start_crawl_date=start_crawl_date,
                end_crawl_date=end_crawl_date,
                start_published_date=start_published_date,
                end_published_date=end_published_date,
                exclude_source_domain=exclude_source_domain,
                category=category,
                livecrawl=livecrawl,
                summary=summary,
            )  # type: ignore[call-overload, misc]
        except Exception as e:
            return repr(e)

Extends

Frequently Asked Questions

What is the ExaFindSimilarResults class?
ExaFindSimilarResults is a class in the langchain codebase, defined in libs/partners/exa/langchain_exa/tools.py.
Where is ExaFindSimilarResults defined?
ExaFindSimilarResults is defined in libs/partners/exa/langchain_exa/tools.py at line 164.
What does ExaFindSimilarResults extend?
ExaFindSimilarResults extends BaseTool.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free