fix(ai): 법령 RAG 로컬 검색 보완 - #35
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a two-tier similarity search strategy to ChangesLegal RAG REST Fallback & Korean Intent Classification
Sequence Diagram(s)sequenceDiagram
participant Caller
participant SupabaseVectorClient
participant Postgres
participant SupabaseREST as Supabase REST API
Caller->>SupabaseVectorClient: similarity_search_legal_documents(query_embedding, top_k)
SupabaseVectorClient->>Postgres: _similarity_search_legal_documents_pgvector()
alt Postgres reachable
Postgres-->>SupabaseVectorClient: ranked rows
SupabaseVectorClient-->>Caller: top-k results
else psycopg.OperationalError
SupabaseVectorClient->>SupabaseVectorClient: supabase_project_ref(database_url)
SupabaseVectorClient->>SupabaseREST: httpx.get /rest/v1/legal_document_chunks
SupabaseREST-->>SupabaseVectorClient: rows with embedding strings
SupabaseVectorClient->>SupabaseVectorClient: parse_pgvector_value + cosine_similarity per row
SupabaseVectorClient-->>Caller: sorted top-k results
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend-ai/app/clients/supabase_client.py`:
- Around line 98-103: The hardcoded limit of 1000 rows in the params dictionary
of the Supabase REST query causes similarity scoring to be computed only on a
truncated subset, potentially missing true nearest neighbors if the
legal_document_chunks table has more rows. Remove the fixed "limit": "1000"
constraint and implement pagination logic to retrieve candidates in batches
before ranking them by similarity score, ensuring all relevant candidates are
considered for scoring. Apply this pagination approach consistently across all
similar REST fallback queries in the file, including the instances around lines
123-124.
- Around line 218-230: The parse_pgvector_value function can raise a ValueError
when converting malformed string items to float in the final return statement,
causing the entire search request to fail instead of gracefully skipping bad
values. Wrap the float conversion in a try-except block within the list
comprehension to catch ValueError exceptions and filter out malformed items that
cannot be converted to float, ensuring the function returns whatever valid float
values it can parse without aborting the request.
In `@backend-ai/tests/test_legal_retriever.py`:
- Around line 180-183: The test settings contain hardcoded credential-shaped
values for supabase_db_url and supabase_service_role_key which violates the
coding guideline requiring credentials to be managed through environment
variables. Replace the hardcoded string literals for supabase_db_url and
supabase_service_role_key with values sourced from environment-backed test
fixtures, such as using environment variable lookups or test configuration
providers, to ensure credentials are not embedded directly in the code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b95e047c-8a38-4885-8696-3c3df9907009
📒 Files selected for processing (5)
.gitignorebackend-ai/app/clients/supabase_client.pybackend-ai/app/graph/nodes/classify_intent.pybackend-ai/tests/test_agent_chat.pybackend-ai/tests/test_legal_retriever.py
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend-ai/app/clients/supabase_client.py (1)
42-51: 🚀 Performance & Scalability | 🟠 MajorFallback fires on every
OperationalError, including transient production failures.
psycopg.OperationalErroris broad—it covers transient connection drops, statement timeouts surfaced as connection resets, and pooler hiccups, not just the locally-blocked port 6543 this PR targets. When triggered in production, the REST path downloads the entirelegal_document_chunkstable page-by-page and computes cosine similarity in Python, causing large memory/latency spikes and silently masking a real database outage instead of failing fast.The
app_envsetting already exists in config and could gate this behavior. Consider using it to restrict the REST fallback to local/dev environments only.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend-ai/app/clients/supabase_client.py` around lines 42 - 51, The try-except block in the similarity search fallback logic is too broad and triggers the REST fallback for all `psycopg.OperationalError` exceptions in production, causing unnecessary performance degradation and masking real database outages. Restrict the REST fallback to only local and development environments by checking the existing `app_env` configuration setting. Only attempt to fallback to `_similarity_search_legal_documents_rest` when `app_env` is not set to production, otherwise let the `psycopg.OperationalError` propagate to fail fast in production environments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@backend-ai/app/clients/supabase_client.py`:
- Around line 42-51: The try-except block in the similarity search fallback
logic is too broad and triggers the REST fallback for all
`psycopg.OperationalError` exceptions in production, causing unnecessary
performance degradation and masking real database outages. Restrict the REST
fallback to only local and development environments by checking the existing
`app_env` configuration setting. Only attempt to fallback to
`_similarity_search_legal_documents_rest` when `app_env` is not set to
production, otherwise let the `psycopg.OperationalError` propagate to fail fast
in production environments.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f76371c1-6ac9-49d4-b301-d877094b5467
📒 Files selected for processing (2)
backend-ai/app/clients/supabase_client.pybackend-ai/tests/test_legal_retriever.py
🚧 Files skipped from review as they are similar to previous changes (1)
- backend-ai/tests/test_legal_retriever.py
변경 내용
연결 이슈
closes #34
테스트
참고
Summary by CodeRabbit
data/legal/.