|
|
|
""" |
|
Quick test for Knowledge Base Browser component |
|
""" |
|
|
|
import os |
|
import sys |
|
import time |
|
from pathlib import Path |
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent / "kb_browser")) |
|
|
|
try: |
|
from kb_browser.retriever import KnowledgeRetriever |
|
from kb_browser import KnowledgeBrowser |
|
|
|
print("β Successfully imported components") |
|
|
|
|
|
print("\n1. Testing basic retriever...") |
|
retriever = KnowledgeRetriever() |
|
print(f"β Retriever initialized with {len(retriever.documents)} sample documents") |
|
|
|
|
|
print("\n2. Testing text search...") |
|
results = retriever.search("retrieval augmented generation", search_type="keyword", k=2) |
|
print(f"β Text search found {results['total_count']} results in {results['search_time']:.3f}s") |
|
|
|
if results['documents']: |
|
doc = results['documents'][0] |
|
print(f" - First result: '{doc['title'][:50]}...'") |
|
print(f" - Relevance: {doc['relevance_score']:.2f}") |
|
|
|
|
|
print("\n3. Testing Gradio component...") |
|
kb_browser = KnowledgeBrowser() |
|
component_results = kb_browser.search("vector databases", max_results=1) |
|
print(f"β Component search returned {len(component_results.get('results', []))} results") |
|
|
|
|
|
print("\n4. Testing API structure...") |
|
api_info = kb_browser.api_info() |
|
properties = api_info['info']['properties'] |
|
print(f"β API has {len(properties)} properties: {list(properties.keys())}") |
|
|
|
|
|
print("\n5. Checking OpenAI integration...") |
|
openai_key = os.getenv('OPENAI_API_KEY') |
|
if openai_key: |
|
print("β OpenAI API key is available") |
|
try: |
|
|
|
semantic_results = retriever.search("LlamaIndex", search_type="semantic", k=1) |
|
print(f"β Semantic search completed in {semantic_results['search_time']:.3f}s") |
|
except Exception as e: |
|
print(f"β Semantic search fell back to text search: {str(e)[:50]}...") |
|
else: |
|
print("β OpenAI API key not found, using text search fallback") |
|
|
|
print("\nπ All tests completed successfully!") |
|
print("\nComponent is ready for:") |
|
print("- Human interactive search") |
|
print("- AI agent integration") |
|
print("- Citation tracking") |
|
print("- Multi-modal search (semantic, keyword, hybrid)") |
|
|
|
except ImportError as e: |
|
print(f"β Import error: {e}") |
|
except Exception as e: |
|
print(f"β Test error: {e}") |
|
import traceback |
|
traceback.print_exc() |