feat: Add semantic memory search endpoint with vector similarity#33
Merged
feat: Add semantic memory search endpoint with vector similarity#33
Conversation
Implement vector similarity search for memories using pgvector's cosine distance operator. This enables semantic retrieval of memories based on embedding similarity. Changes: - Add search_by_similarity method to MemoryRepository using pgvector - Add search_memories method to MemoryService layer - Create SearchMemoriesRequest and SearchMemoriesResponse schemas - Add POST /api/v1/memories/search endpoint to Memory Service API - Endpoint supports scope, topic, and confidence filtering - Returns results with similarity scores (0-1 range, higher is better) - API Gateway already proxies the search endpoint automatically Technical details: - Uses pgvector's cosine_distance operator (<=>) - Converts distance (0-2 range) to similarity score (0-1 range) - Filters out memories without embeddings - Supports pagination with configurable limit (1-100) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implementation Details
Repository Layer (memory_repository.py:344-395)
search_by_similaritymethod using pgvector's cosine distance operatorService Layer (memory_service.py:338-366)
search_memoriesmethod that wraps repository searchinclude_deleted=Falsefor production queriesAPI Layer (memories.py:128-160)
Schemas
SearchMemoriesRequest: Query embedding, optional filters, limit, min_confidenceMemorySearchResult: Individual result with memory data and similarity scoreSearchMemoriesResponse: List of results with total count and limitAPI Gateway
The existing API Gateway catch-all route (
/api/v1/memories/{path:path}) automatically proxies requests to the new search endpoint with no additional configuration needed.Test Plan
🤖 Generated with Claude Code