Home / Function/ arank_fusion() — langchain Function Reference

arank_fusion() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f22e315b_c302_5414_8dd3_04bde7d630dd["arank_fusion()"]
  b484cd3a_bbd0_4ff6_dc8c_3fc1ac219bca["EnsembleRetriever"]
  f22e315b_c302_5414_8dd3_04bde7d630dd -->|defined in| b484cd3a_bbd0_4ff6_dc8c_3fc1ac219bca
  48581379_bf19_22a9_a234_b2b872f7eb03["ainvoke()"]
  48581379_bf19_22a9_a234_b2b872f7eb03 -->|calls| f22e315b_c302_5414_8dd3_04bde7d630dd
  b9cd53a7_287b_9106_31e2_728f202c29e2["_aget_relevant_documents()"]
  b9cd53a7_287b_9106_31e2_728f202c29e2 -->|calls| f22e315b_c302_5414_8dd3_04bde7d630dd
  e4787291_6959_3384_643b_10f54ba9483a["weighted_reciprocal_rank()"]
  f22e315b_c302_5414_8dd3_04bde7d630dd -->|calls| e4787291_6959_3384_643b_10f54ba9483a
  48581379_bf19_22a9_a234_b2b872f7eb03["ainvoke()"]
  f22e315b_c302_5414_8dd3_04bde7d630dd -->|calls| 48581379_bf19_22a9_a234_b2b872f7eb03
  style f22e315b_c302_5414_8dd3_04bde7d630dd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/retrievers/ensemble.py lines 244–286

    async def arank_fusion(
        self,
        query: str,
        run_manager: AsyncCallbackManagerForRetrieverRun,
        *,
        config: RunnableConfig | None = None,
    ) -> list[Document]:
        """Rank fusion.

        Asynchronously retrieve the results of the retrievers
        and use rank_fusion_func to get the final result.

        Args:
            query: The query to search for.
            run_manager: The callback handler to use.
            config: Optional configuration for the retrievers.

        Returns:
            A list of reranked documents.
        """
        # Get the results of all retrievers.
        retriever_docs = await asyncio.gather(
            *[
                retriever.ainvoke(
                    query,
                    patch_config(
                        config,
                        callbacks=run_manager.get_child(tag=f"retriever_{i + 1}"),
                    ),
                )
                for i, retriever in enumerate(self.retrievers)
            ],
        )

        # Enforce that retrieved docs are Documents for each list in retriever_docs
        for i in range(len(retriever_docs)):
            retriever_docs[i] = [
                Document(page_content=doc) if not isinstance(doc, Document) else doc
                for doc in retriever_docs[i]
            ]

        # apply rank fusion
        return self.weighted_reciprocal_rank(retriever_docs)

Domain

Subdomains

Frequently Asked Questions

What does arank_fusion() do?
arank_fusion() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/retrievers/ensemble.py.
Where is arank_fusion() defined?
arank_fusion() is defined in libs/langchain/langchain_classic/retrievers/ensemble.py at line 244.
What does arank_fusion() call?
arank_fusion() calls 2 function(s): ainvoke, weighted_reciprocal_rank.
What calls arank_fusion()?
arank_fusion() is called by 2 function(s): _aget_relevant_documents, ainvoke.

Analyze Your Own Codebase

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

Try Supermodel Free