Set up proper RAG with convex vector search#25
Conversation
…ccess contentType and contentId
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Review Summary by QodoImplement Convex Vector Search for AI Agent Knowledge Retrieval
WalkthroughsDescription• Replace legacy in-memory string-matching with Convex Vector Search for AI knowledge retrieval • Create new aiAgentActionsKnowledge.ts action for vector-based knowledge retrieval • Implement content chunking with overlap for improved embedding quality • Add deduplication logic to vector search results across multiple functions • Deprecate old query-based knowledge endpoints in favor of action-based approach Diagramflowchart LR
Query["Customer Query"]
Embed["Embed Query<br/>text-embedding-3-small"]
VectorSearch["Vector Search<br/>contentEmbeddings"]
Filter["Filter by<br/>Knowledge Sources"]
Dedup["Deduplicate<br/>Results"]
Fetch["Fetch Full<br/>Content"]
Response["AI Response<br/>with Context"]
Query --> Embed
Embed --> VectorSearch
VectorSearch --> Filter
Filter --> Dedup
Dedup --> Fetch
Fetch --> Response
File Changes1. packages/convex/convex/_generated/api.d.ts
|
Code Review by Qodo
1. Manual refs in aiAgentActionsKnowledge
|
CI Feedback 🧐A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
There was a problem hiding this comment.
Pull request overview
Refactors the AI agent’s knowledge retrieval from legacy in-memory string matching to Convex Vector Search over the contentEmbeddings table, aligning the runtime retrieval path with the existing embeddings infrastructure for improved scalability.
Changes:
- Introduces a new internal action (
getRelevantKnowledgeForRuntimeAction) that embeds the query and performs vector similarity search to retrieve knowledge context. - Updates embedding generation to chunk content and store multiple embeddings per content item (supporting higher-quality RAG + deduping).
- Updates suggestions/widget vector-search paths to over-fetch, post-filter by content type, and dedupe results.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/convex/convex/aiAgentActionsKnowledge.ts | Adds internal action implementing vector-based runtime knowledge retrieval. |
| packages/convex/convex/aiAgentActions.ts | Switches runtime knowledge retrieval call site from query → internal action (runAction). |
| packages/convex/convex/aiAgent.ts | Removes legacy string-matching retrieval and deprecates old endpoints by throwing. |
| packages/convex/convex/embeddings.ts | Adds chunking and stores multiple embeddings per content; refactors batch generation to call per-item internal action. |
| packages/convex/convex/suggestions.ts | Adjusts vector search over-fetching, content-type filtering, and deduping for suggestions and widget search. |
| packages/convex/convex/_generated/api.d.ts | Wires new Convex module typing for the added actions module. |
| openspec/** | Documents the new vector-search-based knowledge retrieval design and migration tasks. |
| apps/widget/src/components/conversationView/Footer.tsx | Hides suggestion snippet rendering in the widget footer. |
| ROADMAP.md | Adds roadmap item for widget deep-linking via URL parameters. |
Comments suppressed due to low confidence (1)
packages/convex/convex/aiAgentActions.ts:581
generateResponsenow calls an internal action viarunAction, so unit tests/mocks invokinggenerateResponse._handlerwill need to provide arunActionstub and expected knowledge results. Without updating the tests, this change will throw at runtime whenctx.runActionis undefined.
const knowledgeResults = await runAction(GET_RELEVANT_KNOWLEDGE_FOR_RUNTIME_ACTION_REF, {
workspaceId: args.workspaceId,
query: args.query,
knowledgeSources: settings.knowledgeSources,
limit: 5,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Unused ref warning in packages/convex/convex/embeddings.ts Invalid vector filter chaining in packages/convex/convex/suggestions.ts
This pull request implements a major refactor of the AI agent's knowledge retrieval system to use Convex Vector Search instead of the legacy in-memory string-matching approach. This change significantly improves performance and scalability, especially for large workspaces, by leveraging existing embeddings infrastructure and Convex's native vector search capabilities. The old string-matching logic is removed, and new internal actions are introduced to handle knowledge retrieval via vector similarity.
Key changes include:
AI Knowledge Retrieval Refactor:
Replaced the in-memory string-matching logic (
calculateRelevanceScore,collectRelevantKnowledge, etc.) inaiAgent.tswith a new vector similarity search approach using Convex'svectorSearchon thecontentEmbeddingstable. This improves response times and scalability for the AI agent. [1] [2] [3] [4]Deprecated the old query-based knowledge retrieval endpoints (
getRelevantKnowledge,getRelevantKnowledgeForRuntime) in favor of a new internal action-based endpoint (getRelevantKnowledgeForRuntimeAction). Calls to the deprecated endpoints now throw errors to enforce migration. [1] [2] [3]New Vector Search Action Implementation:
Added
aiAgentActionsKnowledge.tswith a newgetRelevantKnowledgeForRuntimeActioninternal action. This action embeds the incoming query, performs a vector search, filters and deduplicates results, and fetches the final content for the AI agent to use.Updated
aiAgentActions.tsto use the new action reference for runtime knowledge retrieval, including wiring uprunActionand updating the main AI response generation flow to use the new vector-based action. [1] [2] [3] [4]Documentation and Spec Updates:
Other Minor Changes:
These changes collectively modernize the AI agent's retrieval capabilities, reduce latency, and prepare the codebase for future scaling and enhancements.