optional semantic retrieval

This commit is contained in:
2026-04-26 16:05:27 +02:00
parent 7c3cd2ab63
commit 1bac1832f0
11 changed files with 453 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ import subprocess
from repo_registry.core.service import RegistryService
from repo_registry.llm_extraction import ExtractedAbility, ExtractedCapability
from repo_registry.repo_ingestion.git import GitIngestionService
from repo_registry.semantic import HashingEmbeddingProvider
from repo_registry.storage.sqlite import NotFoundError, RegistryStore
@@ -290,6 +291,60 @@ def test_search_filters_by_status_language_and_framework(tmp_path):
assert wrong_capability_results == []
def test_semantic_search_adds_hybrid_matches_without_changing_text_default(tmp_path):
source = tmp_path / "repo"
source.mkdir()
(source / "README.md").write_text(
"# Queue Worker\n\nHandles postponed customer jobs.\n",
encoding="utf-8",
)
text_service = make_service(tmp_path)
repository = text_service.register_repository(
name="Queue Worker",
url=str(source),
description="Processes deferred customer work.",
)
ability_id = text_service.add_ability(
repository.id,
name="Background Job Processing",
description="Run deferred work outside request handling.",
confidence=0.8,
)
capability_id = text_service.add_capability(
repository.id,
ability_id,
name="Process Customer Tasks",
description="Execute queued customer tasks asynchronously.",
confidence=0.7,
)
text_service.add_feature(
repository.id,
capability_id,
name="worker task loop",
type="background worker",
location="worker.py",
confidence=0.6,
)
text_service.analyze_repository(repository.id)
assert text_service.search("customer queued") == []
semantic_service = RegistryService(
text_service.store,
ingestion=GitIngestionService(tmp_path / "checkouts"),
embedding_provider=HashingEmbeddingProvider(),
)
results = semantic_service.search("customer queued")
assert results
assert results[0].match_type in {"capability", "content_chunk"}
assert results[0].matched_field == "semantic"
assert results[0].vector_score > 0
assert results[0].hybrid_score >= results[0].vector_score * 0.35
assert any(result.match_type == "content_chunk" for result in results)
def test_register_repository_imports_metadata_when_name_is_omitted(tmp_path):
source = tmp_path / "metadata-source"
source.mkdir()

View File

@@ -410,11 +410,25 @@ def test_api_service_settings_can_enable_llm_extractor(monkeypatch, tmp_path):
assert service.llm_extractor is not None
def test_api_service_settings_can_enable_hashing_embedding_provider(tmp_path):
service = get_service(
Settings(
database_path=str(tmp_path / "embedding-settings.sqlite3"),
checkout_root=str(tmp_path / "checkouts"),
embedding_provider="hashing",
)
)
assert service.embedding_provider is not None
assert service.embedding_provider.name == "hashing-v1"
def test_settings_can_load_from_environment(monkeypatch):
monkeypatch.setenv("REPO_REGISTRY_DATABASE_PATH", "var/env.sqlite3")
monkeypatch.setenv("REPO_REGISTRY_CHECKOUT_ROOT", "var/env-checkouts")
monkeypatch.setenv("REPO_REGISTRY_LLM_PROVIDER", "mock")
monkeypatch.setenv("REPO_REGISTRY_LLM_MODEL", "demo-model")
monkeypatch.setenv("REPO_REGISTRY_EMBEDDING_PROVIDER", "hashing")
settings = Settings()
@@ -422,6 +436,7 @@ def test_settings_can_load_from_environment(monkeypatch):
assert settings.checkout_root == "var/env-checkouts"
assert settings.llm_provider == "mock"
assert settings.llm_model == "demo-model"
assert settings.embedding_provider == "hashing"
def test_api_analysis_run_loop(tmp_path):