120 llamaindex.core.retrievers.fusion_retriever源码

import asyncio
from enum import Enum
from typing import Dict, List, Optional, Tuple, cast

from llama_index.core.async_utils import run_async_tasks
from llama_index.core.callbacks.base import CallbackManager
from llama_index.core.constants import DEFAULT_SIMILARITY_TOP_K
from llama_index.core.llms.utils import LLMType, resolve_llm
from llama_index.core.prompts import PromptTemplate
from llama_index.core.prompts.mixin import PromptDictType
from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import IndexNode, NodeWithScore, QueryBundle
from llama_index.core.settings import Settings

QUERY_GEN_PROMPT = (
    "You are a helpful assistant that generates multiple search queries based on a "
    "single input query. Generate {num_queries} search queries, one on each line, "
    "related to the following input query:\n"
    "Query: {query}\n"
    "Queries:\n"
)


class FUSION_MODES(str, Enum):
    """Enum for different fusion modes."""

    RECIPROCAL_RANK = "reciprocal_rerank"  # apply reciprocal rank fusion
    RELATIVE_SCORE = "relative_score"  # apply relative score fusion
    DIST_BASED_SCORE = "dist_based_score"  # apply distance-based score fusion
    SIMPLE = "simple"  # simple re-ordering of results based on original scores


class QueryFusionRetriever(BaseRetriever):
    def __init__(
        self,
        retrievers: List[BaseRetriever],
        llm: Optional[LLMType] = None,
        query_gen_prompt: Optional[str] = None,
        mode: FUSION_MODES = FUSION_MODES.SIMPLE,
        similarity_top_k: int = DEFAULT_SIMILARITY_TOP_K,
        num_queries: int = 4,
        use_async: bool = True,
        verbose: bool = False,
        callback_manager: Optional[CallbackManager] = None,
        objects: Optional[List[IndexNode]] = None,
        object_map: Optional[dict] = None,
        retriever_weights: Optional[List[float]] = None,
    ) -> None:
        self.num_queries = num_queries
        self.query_gen_prompt = query_gen_prompt or QUERY_GEN_PROMPT
        self.similarity_top_k = similarity_top_k
        self.mode = mode
        self.use_async = use_async

        self._retrievers = retrievers
        if retriever_weights is None:
            self._retriever_weights = [1.0 / len(retrievers)] * len(retrievers)
        else:
            # Sum of retriever_weights must be 1
            total_weight = sum(retriever_weights)
            self._retriever_weights = [w / total_weight for w in retriever_weights]
        self._llm = (
            resolve_llm(llm, callback_manager=callback_manager) if llm else Settings.llm
        )
        super().__init__(
            callback_manager=callback_manager,
            object_map=object_map,
            objects=objects,
            verbose=verbose,
        )

    def _get_prompts(self) -> PromptDictType:
        """Get prompts."""
        return {
   
   
资源下载链接为: https://pan.quark.cn/s/1bfadf00ae14 在 Linux 中,处理大文件时,尤其是像日志文件这样内容繁多的文件,可能会遇到查找关键字时显示内容过多的情况。例如,对于一个很大的日志文件 info.log,我们想查看包含某段字符(如“1711178968”)的所有日志内容,可以使用命令 cat info.log | grep ‘1711178968’。但如果返回的结果太多,超出了屏幕显示范围,就很难一次性查看完整。 此时,可以通过以下几种方法来解决: 增加时间或行数限制:如果知道日志中包含关键字的时间范围,可以在 grep 命令中加入时间条件,缩小搜索范围,从而减少输出内容。或者,也可以通过限制输出的行数来逐步查看结果。 暂存中间结果:可以使用重定向操作符 >> 将查找结果暂存到一个临时文件中。例如,执行命令 cat info.log | grep ‘1711178968’ >> temp.log,将匹配到的内容保存到 temp.log 文件中。然后,使用 more 或 less 等工具逐页查看 temp.log 文件。more 和 less 都支持分页显示,方便用户逐屏查看文件内容。 按时间截取日志:如果明确知道需要查看的日志时间范围,可以使用 sed 命令来截取特定时段的日志内容。例如,使用命令 sed -n /2 可以截取从指定时间开始到结束时间之间的日志内容。通过这种方式,可以直接定位到目标时间段的日志,避免不必要的内容干扰。 总之,通过这些方法,可以有效解决在处理大文件时查找关键字内容过多的问题,方便用户更高效地查看和分析日志文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

需要重新演唱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值