Home / Function/ unique_by_key() — langchain Function Reference

unique_by_key() — langchain Function Reference

Architecture documentation for the unique_by_key() function in ensemble.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  f67f0af0_2f5f_5c77_60c6_145c0fe80662["unique_by_key()"]
  7c5221fd_0453_d6db_1e3d_2c6252f0057b["ensemble.py"]
  f67f0af0_2f5f_5c77_60c6_145c0fe80662 -->|defined in| 7c5221fd_0453_d6db_1e3d_2c6252f0057b
  e4787291_6959_3384_643b_10f54ba9483a["weighted_reciprocal_rank()"]
  e4787291_6959_3384_643b_10f54ba9483a -->|calls| f67f0af0_2f5f_5c77_60c6_145c0fe80662
  style f67f0af0_2f5f_5c77_60c6_145c0fe80662 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/retrievers/ensemble.py lines 36–50

def unique_by_key(iterable: Iterable[T], key: Callable[[T], H]) -> Iterator[T]:
    """Yield unique elements of an iterable based on a key function.

    Args:
        iterable: The iterable to filter.
        key: A function that returns a hashable key for each element.

    Yields:
        Unique elements of the iterable based on the key function.
    """
    seen = set()
    for e in iterable:
        if (k := key(e)) not in seen:
            seen.add(k)
            yield e

Domain

Subdomains

Frequently Asked Questions

What does unique_by_key() do?
unique_by_key() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/retrievers/ensemble.py.
Where is unique_by_key() defined?
unique_by_key() is defined in libs/langchain/langchain_classic/retrievers/ensemble.py at line 36.
What calls unique_by_key()?
unique_by_key() is called by 1 function(s): weighted_reciprocal_rank.

Analyze Your Own Codebase

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

Try Supermodel Free