[Phase 3] feat(ai): 법률 RAG 검색기 구현 - #21
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 due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaces the hardcoded legal RAG stub with a real two-stage pipeline: a new ChangesLegal RAG Retriever Pipeline
Sequence DiagramsequenceDiagram
participant Client as API Client
participant legal_rag_node as legal_rag Node
participant LegalRetriever
participant EmbeddingClient
participant SupabaseVectorClient as Supabase pgvector
Client->>legal_rag_node: chat message (legal question)
legal_rag_node->>LegalRetriever: retrieve(query, top_k)
LegalRetriever->>LegalRetriever: trim/validate query, clamp top_k
LegalRetriever->>EmbeddingClient: embed_query(query)
EmbeddingClient->>EmbeddingClient: POST /embeddings (bearer auth)
EmbeddingClient-->>LegalRetriever: list[float] vector
LegalRetriever->>SupabaseVectorClient: similarity_search_legal_documents(embedding, top_k)
SupabaseVectorClient->>SupabaseVectorClient: SQL cosine similarity on legal_document_chunks
SupabaseVectorClient-->>LegalRetriever: list[dict] raw rows
LegalRetriever->>LegalRetriever: normalize_legal_card(row) for each row
LegalRetriever-->>legal_rag_node: normalized legal cards
legal_rag_node-->>Client: legal_cards + tool_results{topK, source}
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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: 1
🤖 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 33-35: The psycopg.connect and cursor.execute calls in the
similarity search operation lack explicit timeout parameters, which can cause
indefinite blocking during transient DB or network issues. Add a timeout
parameter to the psycopg.connect call when establishing the connection with
self.database_url to set a connection timeout, and optionally set a query
timeout on the cursor.execute call to ensure the similarity search query cannot
hang indefinitely. This will prevent requests from being blocked by transient
database or network stalls.
🪄 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: 83a6e2f1-ee73-4b15-bf5a-815dd22f068b
📒 Files selected for processing (9)
backend-ai/.env.examplebackend-ai/app/clients/embedding_client.pybackend-ai/app/clients/supabase_client.pybackend-ai/app/core/config.pybackend-ai/app/graph/nodes/legal_rag.pybackend-ai/app/rag/retriever.pybackend-ai/tests/test_agent_chat.pybackend-ai/tests/test_legal_retriever.pyphases/ai-legal-rag/phase3-legal-rag-retriever.md
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend-ai/.env.example (1)
5-6: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueReorder the new timeout keys to keep the example env file lint-clean.
dotenv-linterexpectsSUPABASE_CONNECT_TIMEOUT_SECONDSbeforeSUPABASE_DB_URL, so this placement will keep generating a warning in CI.🤖 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/.env.example` around lines 5 - 6, The dotenv-linter expects environment variables to be in a specific order, with SUPABASE_CONNECT_TIMEOUT_SECONDS appearing before SUPABASE_DB_URL. Reorder the two timeout configuration lines (SUPABASE_CONNECT_TIMEOUT_SECONDS and SUPABASE_STATEMENT_TIMEOUT_MS) in the .env.example file to appear before SUPABASE_DB_URL so the file passes linting without warnings.Source: Linters/SAST tools
backend-ai/tests/test_legal_retriever.py (1)
125-167: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueConsider adding a defensive check before indexing
calls["executes"].The test directly indexes
calls["executes"][0]at line 167 without verifying the list has at least one element. While the current implementation guarantees this, adding a length assertion would make test failures clearer if the implementation changes.♻️ Optional defensive assertion
client.similarity_search_legal_documents([0.1, 0.2], top_k=2) assert calls["connect_kwargs"]["connect_timeout"] == 7 + assert len(calls.get("executes", [])) >= 1, "Expected at least one execute call" assert calls["executes"][0] == ("set local statement_timeout = %s", (3000,))🤖 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/tests/test_legal_retriever.py` around lines 125 - 167, In the test_supabase_vector_client_sets_connection_and_statement_timeouts function, add a defensive assertion before accessing calls["executes"][0] to verify that the list contains at least one element. This will make test failures clearer if the implementation changes and the similarity_search_legal_documents method no longer executes the expected SQL statement. Add the assertion immediately after the client.similarity_search_legal_documents call and before the assert statements that check the execute call parameters.
🤖 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.
Nitpick comments:
In `@backend-ai/.env.example`:
- Around line 5-6: The dotenv-linter expects environment variables to be in a
specific order, with SUPABASE_CONNECT_TIMEOUT_SECONDS appearing before
SUPABASE_DB_URL. Reorder the two timeout configuration lines
(SUPABASE_CONNECT_TIMEOUT_SECONDS and SUPABASE_STATEMENT_TIMEOUT_MS) in the
.env.example file to appear before SUPABASE_DB_URL so the file passes linting
without warnings.
In `@backend-ai/tests/test_legal_retriever.py`:
- Around line 125-167: In the
test_supabase_vector_client_sets_connection_and_statement_timeouts function, add
a defensive assertion before accessing calls["executes"][0] to verify that the
list contains at least one element. This will make test failures clearer if the
implementation changes and the similarity_search_legal_documents method no
longer executes the expected SQL statement. Add the assertion immediately after
the client.similarity_search_legal_documents call and before the assert
statements that check the execute call parameters.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 900b4a18-964d-4dc5-9eb9-31d21f26e38a
📒 Files selected for processing (4)
backend-ai/.env.examplebackend-ai/app/clients/supabase_client.pybackend-ai/app/core/config.pybackend-ai/tests/test_legal_retriever.py
🚧 Files skipped from review as they are similar to previous changes (1)
- backend-ai/app/clients/supabase_client.py
변경 사항
legalCards필드로 정규화legal_ragnode tool metadata를 실제 pgvector source로 갱신테스트
cd backend-ai && .\.venv\Scripts\python.exe -m pytest testsgit diff --checkCloses #20
Summary by CodeRabbit
Release Notes
topKclamping