diff --git a/examples/multi_format_test.py b/examples/multi_format_test.py index 6acec7f..e56253d 100644 --- a/examples/multi_format_test.py +++ b/examples/multi_format_test.py @@ -37,9 +37,11 @@ class MultiFormatRAG(BaseRAG): contexts = [] for doc in docs: source = doc.metadata.get("source_file", "未知来源") + content = doc.page_content.strip() + if source not in sources: sources.append(source) - contexts.append(doc.page_content.strip()) + contexts.append(content) context = "\n\n".join(contexts) sources_str = "、".join(sources) @@ -56,8 +58,8 @@ async def test_multiple_formats(): rag = MultiFormatRAG( vector_store_name="multiformat_kb", retriever_top_k=3, - storage_directory="./test_files", - status_db_path="./status.db", + storage_directory="../test_files", # 相对于examples目录 + status_db_path="../status.db", # 相对于examples目录 ) # 测试文件列表 @@ -92,7 +94,7 @@ async def test_multiple_formats(): format_type = file_info["format"] description = file_info["description"] - file_path = Path("./test_files") / filename + file_path = Path("../test_files") / filename if not file_path.exists(): print(f"❌ {format_type}: {filename} - 文件不存在") @@ -129,14 +131,23 @@ async def test_multiple_formats(): try: answer = await rag.query(query) if "抱歉" not in answer: - # 显示简化的回答 - lines = answer.split('\n') - source_line = next((line for line in lines if line.startswith('基于')), "") - content_lines = [line for line in lines if line.strip() and not line.startswith('基于')] - if content_lines: - print(f" 💡 {content_lines[0][:100]}...") - if source_line: - print(f" 📚 {source_line}") + # 分离来源信息和内容 + parts = answer.split('\n\n', 1) + if len(parts) == 2: + source_info = parts[0] # "基于以下文档..." + content = parts[1] # 实际内容 + + print(f" 📚 {source_info}") + + # 显示内容摘要(前200字符) + if len(content) > 200: + content_preview = content[:200] + "..." + else: + content_preview = content + + print(f" 💡 {content_preview}") + else: + print(f" 💡 {answer}") else: print(f" 💡 {answer}") except Exception as e: diff --git a/status.db b/status.db index e4540be..acef9bf 100644 Binary files a/status.db and b/status.db differ diff --git a/test_files/data_science_feca21d2.txt b/test_files/data_science_feca21d2.txt new file mode 100644 index 0000000..1cc6f29 --- /dev/null +++ b/test_files/data_science_feca21d2.txt @@ -0,0 +1,5 @@ + +NumPy是Python中用于科学计算的基础库,提供多维数组对象。 +Pandas是强大的数据分析和处理库,提供DataFrame数据结构。 +Matplotlib是Python的绘图库,用于创建静态、动态和交互式图表。 +Scikit-learn是机器学习库,提供各种算法和工具。 diff --git a/test_files/python_basics_db5ddb86.txt b/test_files/python_basics_db5ddb86.txt new file mode 100644 index 0000000..8b3388a --- /dev/null +++ b/test_files/python_basics_db5ddb86.txt @@ -0,0 +1,5 @@ + +Python是一种高级编程语言,由Guido van Rossum于1991年创建。 +Python具有简洁易读的语法,适合初学者学习编程。 +Python是解释型语言,支持面向对象、函数式等多种编程范式。 +Python的设计哲学强调代码的可读性和简洁性。 diff --git a/test_files/web_frameworks_b8bf7b11.txt b/test_files/web_frameworks_b8bf7b11.txt new file mode 100644 index 0000000..151a89a --- /dev/null +++ b/test_files/web_frameworks_b8bf7b11.txt @@ -0,0 +1,5 @@ + +Flask是一个轻量级的Python Web框架,易于学习和使用。 +Django是一个功能丰富的Python Web框架,适合大型项目开发。 +FastAPI是现代的Python Web框架,专为构建API而设计。 +Tornado是一个可扩展的非阻塞Web服务器和Web应用框架。