modified PDA with better results and working#237
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f624c40ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import { sanitizeErrorMessage } from "~/app/api/agents/predictive-document-analysis/utils/logging"; | ||
|
|
||
| const embeddingCache = new Map<string, number[]>(); | ||
| const EMBEDDING_MODEL = "text-embedding-3-large"; |
There was a problem hiding this comment.
Keep embedding dimensionality aligned with vector columns
Using text-embedding-3-large here produces 3072-dim vectors by default, while predictive search compares them against pgvector columns that are stored as 1536 dimensions (documentSections.embedding / documentRetrievalChunks.embedding). That mismatch causes ANN/vector SQL to fail at runtime, so contextual matching degrades to empty/fallback results instead of semantic retrieval. Keep the embedding output at 1536 (or migrate column dimensions and indexing together) to avoid breaking retrieval quality.
Useful? React with 👍 / 👎.
| eq(predictiveDocumentAnalysisResults.documentId, BigInt(documentId)), | ||
| eq(predictiveDocumentAnalysisResults.analysisType, typedAnalysisType), | ||
| gt( |
There was a problem hiding this comment.
Scope stream polling to the requested analysis variant
The SSE poll query only matches documentId + analysisType in a 5-minute window, so it can pick up a prior row (including a stale row after forceRefresh=true, or a run with different includeRelatedDocs) and emit that as the final result before the newly queued job finishes. This returns incorrect data nondeterministically under repeated/concurrent requests; the poll predicate needs at least includeRelatedDocs and ideally a persisted jobId.
Useful? React with 👍 / 👎.
| const chunkCount = await db | ||
| .select({ count: sql<number>`count(*)` }) | ||
| .from(documentContextChunks) | ||
| .where(eq(documentContextChunks.documentId, BigInt(documentId))); |
There was a problem hiding this comment.
Fall back to legacy chunks during stream preflight
This preflight check counts only documentContextChunks, but many existing documents still live in legacy pdfChunks (which the synchronous route and Inngest job already handle with fallback). In that case the stream endpoint returns No chunks found and never dispatches analysis even though valid chunks exist. Mirror the same RLM-to-legacy fallback logic here to prevent false 404s.
Useful? React with 👍 / 👎.
No description provided.