Spaces:
Sleeping
Sleeping
File size: 1,521 Bytes
905e3b7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Unit tests for retrieval system."""
import pytest
from app.vector_store.retriever import Retriever
from app.vector_store.chroma_client import ChromaClient
class TestRetrieval:
def test_retriever_init(self):
"""Test retriever initialization."""
retriever = Retriever()
assert retriever is not None
assert retriever.vector_store is not None
def test_hybrid_search(self):
"""Test hybrid search functionality."""
retriever = Retriever()
# Add some test documents
test_docs = [
{"document": "This is a test document about contracts.", "metadata": {"source": "test1"}},
{"document": "This document discusses payment terms and conditions.", "metadata": {"source": "test2"}},
{"document": "This is about legal liability and termination clauses.", "metadata": {"source": "test3"}}
]
# Search
results = retriever.hybrid_search("contract terms", k=2)
assert results is not None
assert len(results) <= 2
def test_semantic_search(self):
"""Test semantic search."""
retriever = Retriever()
results = retriever.vector_store.search("test query", k=3)
assert results is not None
def test_bm25_index(self):
"""Test BM25 index building."""
retriever = Retriever()
assert retriever.bm25_index is not None
if __name__ == "__main__":
pytest.main([__file__]) |