- Add vector store with sentence-transformers for semantic search - FastAPI backend with /chat and /health endpoints - Conversation state persistence via SQLite - OpenRouter integration with structured JSON responses - Discord bot with /ask slash command and reply-based follow-ups - Automated Gitea issue creation for unanswered questions - Docker support with docker-compose for easy deployment - Example rule file and ingestion script - Comprehensive documentation in README
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
"""Basic test to verify the vector store and ingestion."""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "app"))
|
|
|
|
from app.config import settings
|
|
from app.vector_store import VectorStore
|
|
from app.models import RuleDocument, RuleMetadata
|
|
|
|
|
|
def test_ingest_example_rule():
|
|
"""Test ingesting the example rule and searching."""
|
|
# Override settings for test
|
|
test_data_dir = Path(__file__).parent.parent / "data"
|
|
test_chroma_dir = test_data_dir / "chroma_test"
|
|
test_rules_dir = test_data_dir / "rules"
|
|
|
|
vs = VectorStore(test_chroma_dir, settings.embedding_model)
|
|
vs.clear_all()
|
|
|
|
# Load example rule
|
|
example_rule_path = test_rules_dir / "example_rule.md"
|
|
if not example_rule_path.exists():
|
|
print(f"Example rule not found at {example_rule_path}, skipping test")
|
|
return
|
|
|
|
content = example_rule_path.read_text(encoding="utf-8")
|
|
import re
|
|
import yaml
|
|
|
|
pattern = r"^---\s*\n(.*?)\n---\s*\n(.*)$"
|
|
match = re.match(pattern, content, re.DOTALL)
|
|
if match:
|
|
metadata_dict = yaml.safe_load(match.group(1))
|
|
body = match.group(2).strip()
|
|
metadata = RuleMetadata(**metadata_dict)
|
|
doc = RuleDocument(
|
|
metadata=metadata, content=body, source_file=str(example_rule_path)
|
|
)
|
|
vs.add_document(doc)
|
|
|
|
# Verify count
|
|
assert vs.count() == 1, f"Expected 1 rule, got {vs.count()}"
|
|
|
|
# Search for relevant content
|
|
results = vs.search("runner steal base", top_k=5)
|
|
assert len(results) > 0, "Expected at least one search result"
|
|
assert (
|
|
results[0].rule_id == "5.2.1(b)"
|
|
), f"Expected rule 5.2.1(b), got {results[0].rule_id}"
|
|
|
|
print("✓ Test passed: Ingestion and search work correctly")
|
|
print(f" Found rule: {results[0].title}")
|
|
print(f" Similarity: {results[0].similarity:.2%}")
|
|
|
|
# Cleanup
|
|
vs.clear_all()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_ingest_example_rule()
|