Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented May 30, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a unified API endpoint for generating text embeddings with support for multiple providers and customizable settings.
    • Added a new API endpoint for searching content by query and platform filters, returning relevant results.
    • Expanded type definitions to include provider options and embedding settings for greater flexibility.
    • Provided utility functions to manage embedding models, default dimensions, and table metadata.
  • Refactor

    • Consolidated embedding API routes for improved maintainability and provider extensibility.
  • Chores

    • Enhanced internal mappings and configuration management for embedding providers and models.

@linear
Copy link

linear bot commented May 30, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 30, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This change refactors and generalizes the API for text embeddings by removing the provider-specific OpenAI embeddings route and introducing a unified embeddings API supporting multiple providers. It adds new type definitions, utility functions for handling embeddings, and enhances Supabase search functionality using embeddings.

Changes

File(s) Change Summary
apps/website/app/api/embeddings/openai/small/route.ts Removed provider-specific API route for OpenAI embeddings.
apps/website/app/api/embeddings/route.ts Added new generic embeddings API route supporting multiple providers and improved error handling.
apps/website/app/api/supabase/rpc/search-content/route.ts Introduced new Supabase RPC route for content search using generated embeddings.
apps/website/app/types/llm.ts Added new types: Provider (provider union) and EmbeddingSettings (model, dimensions).
apps/website/app/utils/llm/embeddings.ts Added generic embedding generation utilities, supporting OpenAI and future providers.
apps/website/app/utils/llm/providers.ts Added provider configuration mapping for supported LLM providers.
apps/website/app/utils/supabase/dbUtils.ts Added embedding table metadata types, mappings, and a utility to resolve known embeddings.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as /api/embeddings
    participant EmbeddingUtil as genericEmbedding
    participant Provider as OpenAI API

    Client->>API: POST /api/embeddings (input, settings, provider)
    API->>EmbeddingUtil: genericEmbedding(input, settings, provider)
    EmbeddingUtil->>Provider: Request embeddings (if provider is openai)
    Provider-->>EmbeddingUtil: Embedding response
    EmbeddingUtil-->>API: Embedding vectors
    API-->>Client: Embedding vectors (JSON)
Loading
sequenceDiagram
    participant Client
    participant API as /api/supabase/rpc/search-content
    participant EmbeddingUtil as genericEmbedding
    participant Supabase

    Client->>API: POST /api/supabase/rpc/search-content (query, platform_ids)
    API->>EmbeddingUtil: Generate embedding for query
    EmbeddingUtil-->>API: Embedding vector
    API->>Supabase: RPC match_embeddings_for_subset_nodes(embedding, platform_ids)
    Supabase-->>API: Matching content results
    API-->>Client: Search results (JSON)
Loading

Possibly related PRs

Suggested reviewers

  • mdroidian

Poem

In the warren of code, a new path is found,
Where embeddings leap, no longer tightly bound.
Providers now gather, their settings aligned,
Supabase searching, with vectors combined.
Rabbits rejoice, as the APIs grow—
Hopping through models, wherever they go! 🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 30, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@vercel
Copy link

vercel bot commented May 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discourse-graph ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 2:58pm

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (4)
apps/website/app/api/embeddings/route.ts (1)

37-37: Update the error log message to reflect the generic nature of this API.

The error message still references "OpenAI Embeddings API" but this is now a generic embeddings API that supports multiple providers.

-    console.error("Error calling OpenAI Embeddings API:", error);
+    console.error("Error calling Embeddings API:", error);
apps/website/app/utils/llm/embeddings.ts (1)

46-46: Use strict equality comparison.

Use === instead of == for type-safe comparison.

-  if (provider == "openai") {
+  if (provider === "openai") {
apps/website/app/api/supabase/rpc/search-content/route.ts (1)

61-61: Correct the logging path to match actual route.

The log message shows /api/supabase/rpc/search but the actual file path suggests the route is /api/supabase/rpc/search-content.

-  console.log("[API Route] POST /api/supabase/rpc/search: Request received");
+  console.log("[API Route] POST /api/supabase/rpc/search-content: Request received");
apps/website/app/utils/supabase/dbUtils.ts (1)

35-35: Consider making the provider parameter required.

Defaulting the provider to "openai" when not specified could mask configuration errors. Consider making the provider parameter required or at least logging when the default is used.

-  const embeddingName =
-    KNOWN_EMBEDDINGS[`${provider || "openai"}-${model}-${dimensions}`];
+  const actualProvider = provider || "openai";
+  if (!provider) {
+    console.warn(`No provider specified for model ${model}, defaulting to '${actualProvider}'`);
+  }
+  const embeddingName = KNOWN_EMBEDDINGS[`${actualProvider}-${model}-${dimensions}`];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c90190 and 4de66e8.

📒 Files selected for processing (7)
  • apps/website/app/api/embeddings/openai/small/route.ts (0 hunks)
  • apps/website/app/api/embeddings/route.ts (1 hunks)
  • apps/website/app/api/supabase/rpc/search-content/route.ts (1 hunks)
  • apps/website/app/types/llm.ts (2 hunks)
  • apps/website/app/utils/llm/embeddings.ts (1 hunks)
  • apps/website/app/utils/llm/providers.ts (2 hunks)
  • apps/website/app/utils/supabase/dbUtils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/website/app/api/embeddings/openai/small/route.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
apps/website/app/utils/llm/providers.ts (1)
apps/website/app/types/llm.ts (2)
  • Provider (1-1)
  • LLMProviderConfig (32-39)
apps/website/app/api/embeddings/route.ts (3)
apps/website/app/types/llm.ts (2)
  • EmbeddingSettings (24-27)
  • Provider (1-1)
apps/website/app/utils/llm/cors.ts (1)
  • cors (12-39)
apps/website/app/utils/llm/embeddings.ts (1)
  • genericEmbedding (41-59)
apps/website/app/utils/supabase/dbUtils.ts (1)
packages/database/types.gen.ts (1)
  • Database (9-645)
🔇 Additional comments (12)
apps/website/app/utils/llm/providers.ts (2)

1-1: LGTM!

Good addition of the Provider type to the imports to support the new configuration mapping.


62-66: LGTM!

Excellent addition of the centralized provider configuration mapping. This provides type-safe access to provider configurations and supports the new generalized embedding architecture well.

apps/website/app/types/llm.ts (2)

1-1: LGTM!

Well-defined Provider type that clearly represents the supported LLM providers.


24-27: LGTM!

Clean and focused EmbeddingSettings type. The optional dimensions field is appropriate since not all embedding models support custom dimensions.

apps/website/app/api/embeddings/route.ts (4)

6-10: LGTM!

Well-defined request body type that clearly specifies the expected parameters with appropriate optional provider defaulting to OpenAI.


19-25: LGTM!

Excellent input validation that handles both string and array inputs appropriately.


27-35: LGTM!

Good error handling for when embedding generation fails, with appropriate HTTP status codes.


56-58: LGTM!

Proper OPTIONS handler for CORS preflight requests.

apps/website/app/utils/llm/embeddings.ts (2)

27-38: LGTM!

Excellent timeout handling with Promise.race and proper return type handling for both string and array inputs.


49-57: LGTM!

Excellent commentary on the implementation tradeoffs between using provider-specific libraries vs direct API calls. This provides valuable context for future development decisions.

apps/website/app/api/supabase/rpc/search-content/route.ts (1)

120-123: LGTM on OPTIONS handler.

The OPTIONS handler correctly implements CORS preflight handling with appropriate status code and CORS middleware.

apps/website/app/utils/supabase/dbUtils.ts (1)

8-11: Well-structured type definition.

The EmbeddingTableData type provides good structure for embedding table metadata with appropriate constraints using database table keys.

@mdroidian
Copy link
Contributor

Closed in favor of #185

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

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants