Home / Function/ afrom_examples() — langchain Function Reference

afrom_examples() — langchain Function Reference

Architecture documentation for the afrom_examples() function in semantic_similarity.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  92ff0030_066c_8652_d349_5e51c03f594e["afrom_examples()"]
  67ba8b66_097f_0cce_e1c7_525373834e2e["MaxMarginalRelevanceExampleSelector"]
  92ff0030_066c_8652_d349_5e51c03f594e -->|defined in| 67ba8b66_097f_0cce_e1c7_525373834e2e
  9b0bcff8_a92b_8345_a2e7_026bb6378f75["afrom_examples()"]
  9b0bcff8_a92b_8345_a2e7_026bb6378f75 -->|calls| 92ff0030_066c_8652_d349_5e51c03f594e
  9b0bcff8_a92b_8345_a2e7_026bb6378f75["afrom_examples()"]
  92ff0030_066c_8652_d349_5e51c03f594e -->|calls| 9b0bcff8_a92b_8345_a2e7_026bb6378f75
  5599ebbf_7d2d_cb9f_f035_4928a6716083["_example_to_text()"]
  92ff0030_066c_8652_d349_5e51c03f594e -->|calls| 5599ebbf_7d2d_cb9f_f035_4928a6716083
  style 92ff0030_066c_8652_d349_5e51c03f594e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/example_selectors/semantic_similarity.py lines 314–358

    async def afrom_examples(
        cls,
        examples: list[dict],
        embeddings: Embeddings,
        vectorstore_cls: type[VectorStore],
        *,
        k: int = 4,
        input_keys: list[str] | None = None,
        fetch_k: int = 20,
        example_keys: list[str] | None = None,
        vectorstore_kwargs: dict | None = None,
        **vectorstore_cls_kwargs: Any,
    ) -> MaxMarginalRelevanceExampleSelector:
        """Create k-shot example selector using example list and embeddings.

        Reshuffles examples dynamically based on Max Marginal Relevance.

        Args:
            examples: List of examples to use in the prompt.
            embeddings: An initialized embedding API interface, e.g. OpenAIEmbeddings().
            vectorstore_cls: A vector store DB interface class, e.g. FAISS.
            k: Number of examples to select.
            fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
            input_keys: If provided, the search is based on the input variables
                instead of all variables.
            example_keys: If provided, keys to filter examples to.
            vectorstore_kwargs: Extra arguments passed to similarity_search function
                of the `VectorStore`.
            vectorstore_cls_kwargs: optional kwargs containing url for vector store

        Returns:
            The ExampleSelector instantiated, backed by a vector store.
        """
        string_examples = [cls._example_to_text(eg, input_keys) for eg in examples]
        vectorstore = await vectorstore_cls.afrom_texts(
            string_examples, embeddings, metadatas=examples, **vectorstore_cls_kwargs
        )
        return cls(
            vectorstore=vectorstore,
            k=k,
            fetch_k=fetch_k,
            input_keys=input_keys,
            example_keys=example_keys,
            vectorstore_kwargs=vectorstore_kwargs,
        )

Domain

Subdomains

Called By

Frequently Asked Questions

What does afrom_examples() do?
afrom_examples() is a function in the langchain codebase, defined in libs/core/langchain_core/example_selectors/semantic_similarity.py.
Where is afrom_examples() defined?
afrom_examples() is defined in libs/core/langchain_core/example_selectors/semantic_similarity.py at line 314.
What does afrom_examples() call?
afrom_examples() calls 2 function(s): _example_to_text, afrom_examples.
What calls afrom_examples()?
afrom_examples() is called by 1 function(s): afrom_examples.

Analyze Your Own Codebase

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

Try Supermodel Free