Compare commits

...

2 Commits

1 changed files with 3 additions and 3 deletions

View File

@ -150,7 +150,7 @@ SEARCH_ENGINES = {
} }
def search_result2docs(search_results, engine_name) -> List[Document]: def search_result2docs(search_results, engine_name, top_k) -> List[Document]:
docs = [] docs = []
if engine_name == "zhipu_search": if engine_name == "zhipu_search":
try: try:
@ -161,7 +161,7 @@ def search_result2docs(search_results, engine_name) -> List[Document]:
results = [] results = []
# 遍历并处理每个结果 # 遍历并处理每个结果
for idx, result in enumerate(results, 1): for idx, result in enumerate(results[:top_k], 1):
doc = Document( doc = Document(
page_content=result["content"], page_content=result["content"],
metadata={"link": result["link"], "title": result["title"]} metadata={"link": result["link"], "title": result["title"]}
@ -194,7 +194,7 @@ def search_engine(query: str, top_k: int = 0, engine_name: str = "", config: dic
text=query, config=config["search_engine_config"][engine_name], top_k=top_k text=query, config=config["search_engine_config"][engine_name], top_k=top_k
) )
docs = [x for x in search_result2docs(results, engine_name) if x.page_content and x.page_content.strip()] docs = [x for x in search_result2docs(results, engine_name, top_k) if x.page_content and x.page_content.strip()]
print(f"len(docs): {len(docs)}") print(f"len(docs): {len(docs)}")
print(f"docs: {docs}") print(f"docs: {docs}")
return {"docs": docs, "search_engine": engine_name} return {"docs": docs, "search_engine": engine_name}