文件变更

This commit is contained in:
2026-04-20 14:05:57 +08:00
parent 3c906e91d9
commit 4e981e9dcf
28 changed files with 474 additions and 490 deletions

View File

@@ -2,32 +2,33 @@
重排序器模块 (适配版)
使用远程 llama.cpp 服务 (兼容 OpenAI Rerank API) 替代本地 Cross-Encoder
"""
import os
import requests
from typing import List
from typing import List, Optional
from langchain_core.documents import Document
class LLaMaCPPReranker:
"""使用远程 llama.cpp 服务对检索结果重排序。"""
def __init__(self,
base_url: str = "http://127.0.0.1:8083",
base_url: str,
api_key: str,
top_n: int = 5,
api_key: str = "huang1998", # 你设置的 LLAMA_ARG_API_KEY
timeout: int = 60):
"""
初始化远程重排序器
Args:
base_url: llama.cpp 服务的地址和端口。
base_url: llama.cpp 服务的地址和端口,默认为环境变量 LLAMACPP_RERANKER_URL 或 "http://127.0.0.1:8083"
top_n: 返回前 N 个结果。
api_key: 在容器中设置的 API 密钥。
api_key: API 密钥,默认为环境变量 LLAMACPP_API_KEY 或 "huang1998"
timeout: 请求超时时间(秒)。
"""
self.base_url = base_url.rstrip('/')
self.base_url = base_url
self.api_key = api_key
self.top_n = top_n
self.api_key = api_key
self.timeout = timeout
self.endpoint = f"{self.base_url}/v1/rerank"
self.endpoint = f"{self.base_url}/rerank"
def compress_documents(
self, documents: List[Document], query: str