# Issue #70: [KNOW-018] Semantic Search API ## Objective Implement semantic (vector) search endpoint that uses embeddings generated by issue #69 to enable natural language search over knowledge entries. ## Approach 1. Review existing embedding schema and pgvector setup 2. Review OllamaEmbeddingService from issue #69 3. Create DTOs for semantic search request/response 4. Write tests first (TDD) 5. Implement semantic search in SearchService using pgvector cosine similarity 6. Create controller endpoint POST /api/knowledge/search/semantic 7. Add configurable similarity threshold 8. Test with real queries 9. Run quality checks and code review ## Progress - [x] Create scratchpad - [x] Review existing code (embedding schema, OllamaEmbeddingService) - [x] Add similarity threshold environment variable - [x] Write tests (TDD - RED) - [x] Update SearchService to use OllamaEmbeddingService instead of OpenAI (TDD - GREEN) - [x] Update hybridSearch to use OllamaEmbeddingService - [x] Update test files to include OllamaEmbeddingService mocks - [x] All tests passing - [x] Type check and build successful - [x] Run code review (quality gates passed) - [x] Run QA checks (prettier, lint, typecheck all passed) - [x] Commit changes - [ ] Close issue ## Testing - Unit tests for SearchService.semanticSearch() - Controller tests for POST /api/knowledge/search/semantic - Integration tests with real embeddings - Target: 85%+ coverage ## Notes - Use pgvector cosine similarity operator (<=>) - Lower distance = higher similarity - Results should include similarity scores - Similarity threshold should be configurable via environment variable - Reuse OllamaEmbeddingService from issue #69 ## Findings - The semantic search endpoint already exists in search.controller.ts (line 111) - The SearchService already has semanticSearch() method (line 449) - BUT: It currently uses OpenAI-based EmbeddingService instead of OllamaEmbeddingService - Need to update SearchService to inject and use OllamaEmbeddingService - Need to add configurable similarity threshold - Controller endpoint already properly configured with guards and permissions