Skip to content

feat: Add native Convex vector search for websitePages #77

Closed as not planned

Description

@larryro

Problem Statement

Currently crawled web pages are stored in the websitePages table but are not effectively utilized for semantic search. The existing RAG implementation relies on an external service (Cognee + PGVector), which adds system complexity.

Requirements

  • Maintain vector tables natively within Convex
  • Users should only need to configure environment variables, not modify schema.ts
  • Support different embedding model dimensions
  • No migration of existing data required

Current State

Data Storage:

  • websitePages table stores crawled content (url, title, content, metadata)

Existing RAG Architecture:

  • External RAG service: Cognee + PGVector (localhost:8001)
  • Sync workflow: website_pages_rag_sync

Proposed Solution

Pre-defined Multi-dimension Vector Tables: Define multiple vector tables with different dimensions in the schema. Users select which one to use via the EMBEDDING_DIMENSIONS environment variable.

Supported Dimensions

Dimension Table Name Suitable Model
256 websitePageEmbeddings256 text-embedding-3-small (reduced)
512 websitePageEmbeddings512 text-embedding-3-small (reduced)
1024 websitePageEmbeddings1024 text-embedding-3-small (reduced)
1536 websitePageEmbeddings1536 text-embedding-3-small (default)
2048 websitePageEmbeddings2048 Convex maximum supported

Note: Convex vectorIndex supports a maximum of 2048 dimensions

Affected Components

  • convex/schema.ts - Add 5 multi-dimension embedding tables
  • convex/lib/embedding_config.ts - New dimension configuration utilities
  • convex/website_page_embeddings.ts - New embedding generation and search logic
  • convex/agent_tools/website_pages/website_pages_search_tool.ts - New Agent search tool
  • convex/agent_tools/tool_registry.ts - Register new tool
  • convex/model/websites/bulk_upsert_pages.ts - Auto-trigger embedding generation
  • .env.example - Add EMBEDDING_DIMENSIONS documentation

Acceptance Criteria

  • 5 multi-dimension embedding tables created successfully
  • EMBEDDING_DIMENSIONS env var correctly switches the active table
  • Newly crawled pages automatically generate embeddings
  • Semantic search returns relevant results
  • Agent can search via website_pages_search tool
  • Search supports filtering by organizationId and websiteId

🤖 Generated with Claude Code

Activity

  1. larryro commented on Jan 4, 2026

    @larryro
    ContributorAuthor

    Implementation Plan

    Phase 1: Schema Definition

    1.1 Create multi-dimension embedding tables

    Add to convex/schema.ts:

    // Website Page Embeddings - vector embeddings for semantic search
    // Multiple tables for different embedding dimensions (256, 512, 1024, 1536, 2048)
    
    websitePageEmbeddings256: defineTable({
      organizationId: v.string(),
      websiteId: v.id('websites'),
      pageId: v.id('websitePages'),
      embedding: v.array(v.float64()),
      url: v.string(),
      title: v.optional(v.string()),
      contentHash: v.string(),
      chunkIndex: v.optional(v.number()),
      chunkContent: v.optional(v.string()),
      createdAt: v.number(),
      updatedAt: v.number(),
    })
      .index('by_organizationId', ['organizationId'])
      .index('by_pageId', ['pageId'])
      .index('by_organizationId_and_pageId', ['organizationId', 'pageId'])
      .vectorIndex('by_embedding', {
        vectorField: 'embedding',
        dimensions: 256,
        filterFields: ['organizationId', 'websiteId'],
      }),
    
    // Repeat for 512, 1024, 1536, 2048 dimensions...

    Phase 2: Dimension Configuration Layer

    2.1 Create configuration utilities

    New file: convex/lib/embedding_config.ts

    • SUPPORTED_DIMENSIONS constant
    • getEmbeddingDimension() - reads from env var
    • getEmbeddingTableName() - returns table name
    • getRecommendedEmbeddingModel() - model selection based on dimension

    Phase 3: Embedding Generation

    3.1 Create embedding action

    New file: convex/website_page_embeddings.ts

    • generateEmbedding - internal action to generate and store embedding
    • getByPageId - query existing embedding
    • upsert - create or update embedding record
    • Content hash for change detection
    • Auto model selection based on dimension

    Phase 4: Vector Search

    4.1 Create search action

    Add to convex/website_page_embeddings.ts:

    • search action - performs vector search
    • Supports organizationId and websiteId filters
    • Returns enriched results with page content

    Phase 5: Agent Tool Integration

    5.1 Create search tool

    New file: convex/agent_tools/website_pages/website_pages_search_tool.ts

    • website_pages_search tool definition
    • Natural language query support
    • Optional website filtering

    5.2 Register tool

    Update convex/agent_tools/tool_registry.ts

    Phase 6: Auto-sync Trigger

    6.1 Trigger embedding on page save

    Update convex/model/websites/bulk_upsert_pages.ts:

    • Schedule embedding generation after page upsert

    Files to Modify

    File Changes
    convex/schema.ts Add 5 multi-dimension embedding tables
    convex/lib/embedding_config.ts New - dimension config utilities
    convex/website_page_embeddings.ts New - embedding generation & search
    convex/agent_tools/website_pages/website_pages_search_tool.ts New - Agent tool
    convex/agent_tools/tool_registry.ts Register new tool
    convex/model/websites/bulk_upsert_pages.ts Auto-trigger embedding
    .env.example Add EMBEDDING_DIMENSIONS docs

    Environment Variable Configuration

    # Embedding dimension configuration
    # Supported values: 256, 512, 1024, 1536 (default), 2048
    EMBEDDING_DIMENSIONS=1536

    Potential Risks

    • Dimension switching: Changing EMBEDDING_DIMENSIONS writes to a different table; old data won't migrate automatically
    • Convex limit: Maximum 2048 dimensions; 3072-dim models need reduction or external RAG
    • Storage cost: Each dimension table stores data independently

    Testing Strategy

    • Unit test dimension config utilities
    • Integration test embedding generation
    • E2E test vector search with sample data
    • Verify tool registration and agent usage

    🤖 Generated with Claude Code

  2. added
    feat
    and removed on Feb 1, 2026
  3. yannickmonney commented on May 31, 2026

    @yannickmonney
    Contributor

    Triaged — keeping open, but flagging for design review. Semantic search currently goes through the external RAG service (services/rag/); the websitePages table + a website_pages_rag_sync flow already exist. Adding native Convex vector search for websitePages is a meaningful architectural choice that competes with the external-RAG direction (cf. #662, #69), so it's worth a design decision on which path to invest in before building. Assigned to me.

  4. added
    needs discussion
    on May 31, 2026
  5. larryro commented on Jun 1, 2026

    @larryro
    ContributorAuthor

    @yannickmonney
    Adding native Convex vector search for websitePages is a meaningful architectural choice that competes with the external-RAG direction (cf. #662, #69), so it's worth a design decision on which path to invest in before building.

    Closing this in favor of the external RAG direction — the design question is already settled by prior experience.

    We tried native Convex vector search for this kind of workload before, and it doesn't hold up. Storing embeddings + running a vectorIndex over them at our scale pushes the deployment into failure modes that affect everything, not just search:

    • Convex dashboard hangs / becomes unusable
    • backend crashes abnormally
    • deploys get blocked — you can't push new code while the backend is in that state

    Those are deployment-wide outages, not isolated search degradation, so the risk far outweighs the benefit of dropping the external service. Semantic search already works through services/rag/ (Cognee + PGVector) plus the website_pages_rag_sync flow, so there's no functional gap to close here.

    Staying on external RAG (cf. #662, #69). Closing as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featneeds discussionpriority: mediumservice: platform

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions