Skip to content

Conversation

@jpoehnelt
Copy link
Owner

@jpoehnelt jpoehnelt commented Mar 27, 2025

Summary by CodeRabbit

  • New Features
    • Introduced robust semantic search and document classification capabilities that enhance text analysis in spreadsheet and document workflows.
  • Documentation
    • Added a comprehensive guide detailing how to leverage vector embedding techniques for semantic text processing.
  • Chores
    • Improved development tooling and environment configurations for streamlined build, formatting, and deployment.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several new configuration files, build scripts, documentation, and source code modules to support a Google Apps Script project centered on vector embeddings. It adds settings for VSCode formatting, project configuration for clasp, TypeScript, and Apps Script runtime, and a comprehensive README guide that details semantic search and text similarity functions. Additionally, new source files implement core vector operations, embedding generation via an API call, and compatibility fixes with a polyfill.

Changes

File(s) Change Summary
.vscode/settings.json Added VSCode settings to set Prettier as the default formatter.
projects/vector-embeddings/.clasp.json, …/package.json, …/src/appsscript.json, …/tsconfig.json Introduced configuration files for Google Apps Script, project metadata, OAuth scopes, and TypeScript compiler options.
projects/vector-embeddings/README.md Added comprehensive documentation on vector embeddings, semantic search, and example functions.
projects/vector-embeddings/build.js Added an esbuild-based bundling script to compile TypeScript and copy necessary files.
projects/vector-embeddings/src/index.ts, …/src/internal.d.ts, …/src/main.js, …/src/examples.js, …/src/tools.js Introduced new source files defining vector embedding functions, semantic search logic, similarity calculations, type declarations, and utility vector operations.
projects/vector-embeddings/polyfill.js Added assignment for globalThis.window to ensure compatibility across different environments.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant SS as SEMANTIC_SEARCH
    participant BE as batchedEmbeddings_
    participant GC as Google Cloud Vertex AI
    participant VT as Vector Tools
    
    U->>SS: Initiate semantic search with query & corpus
    SS->>BE: Request text embeddings
    BE->>GC: Call AI API for embeddings
    GC-->>BE: Return embeddings
    BE-->>SS: Deliver embeddings
    SS->>VT: Compute similarity scores
    VT-->>SS: Return similarity data
    SS->>U: Return sorted results
Loading

Poem

Oh, I’m a bunny, hopping with delight,
New code sprouts like carrots in the light.
Embeddings bloom in fields of text so grand,
Semantic searches at my command.
I nibble bugs and polish every byte,
Hoppity cheers for code shining bright!
🐰✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd2e691 and df60a44.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/vector-embeddings/Screenshot 2025-03-27 at 1.27.28 PM.png is excluded by !**/*.png
📒 Files selected for processing (13)
  • .vscode/settings.json (1 hunks)
  • projects/vector-embeddings/.clasp.json (1 hunks)
  • projects/vector-embeddings/README.md (1 hunks)
  • projects/vector-embeddings/build.js (1 hunks)
  • projects/vector-embeddings/package.json (1 hunks)
  • projects/vector-embeddings/polyfill.js (1 hunks)
  • projects/vector-embeddings/src/appsscript.json (1 hunks)
  • projects/vector-embeddings/src/examples.js (1 hunks)
  • projects/vector-embeddings/src/index.ts (1 hunks)
  • projects/vector-embeddings/src/internal.d.ts (1 hunks)
  • projects/vector-embeddings/src/main.js (1 hunks)
  • projects/vector-embeddings/src/tools.js (1 hunks)
  • projects/vector-embeddings/tsconfig.json (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @jpoehnelt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces a new project, vector-embeddings, which demonstrates how to use Google's Vertex AI to generate vector embeddings within Google Apps Script. The project includes code for generating embeddings, calculating similarity between embeddings, and building a simple semantic search function. It also provides examples of how to use vector embeddings in Google Sheets and for document classification. The changes include adding necessary dependencies, build scripts, and configuration files for the new project.

Highlights

  • New Project: vector-embeddings: Introduces a new project demonstrating vector embeddings with Google Apps Script and Vertex AI.
  • Embedding Generation: Implements functions to generate vector embeddings from text using Vertex AI.
  • Similarity Calculation: Includes functions to calculate the cosine similarity between two embeddings.
  • Semantic Search: Provides a basic semantic search function that leverages vector embeddings.
  • Google Sheets Integration: Demonstrates how to use vector embeddings in Google Sheets with a custom function.
  • Document Classification: Shows how to use embeddings to automatically categorize documents.
  • Build Process: Adds a build script using esbuild to bundle the Apps Script project.

Changelog

Click here to see the changelog
  • .vscode/settings.json
    • Configures the default formatter to be esbenp.prettier-vscode for javascript files.
  • pnpm-lock.yaml
    • Adds dependencies for the vector-embeddings project, including @google/clasp, @types/google-apps-script, and esbuild.
  • projects/vector-embeddings/.clasp.json
    • Adds a clasp configuration file for the vector-embeddings project, specifying the script ID, root directory, project ID, and file extensions.
  • projects/vector-embeddings/README.md
    • Creates a comprehensive README file explaining how to use vector embeddings in Google Apps Script with Vertex AI, including code examples and real-world applications.
  • projects/vector-embeddings/build.js
    • Adds a build script using esbuild to bundle the Apps Script project, including minification and banner injection.
  • projects/vector-embeddings/package.json
    • Creates a package.json file for the vector-embeddings project, specifying dependencies, scripts, and other metadata.
  • projects/vector-embeddings/polyfill.js
    • Adds a polyfill to define globalThis.window for compatibility with certain libraries.
  • projects/vector-embeddings/src/appsscript.json
    • Adds an appsscript.json file specifying the project's time zone, dependencies, exception logging, runtime version, and OAuth scopes.
  • projects/vector-embeddings/src/examples.js
    • Adds example functions for semantic search, Google Sheets integration, and document classification.
  • projects/vector-embeddings/src/index.ts
    • Creates an empty index.ts file, likely serving as an entry point for the TypeScript build process.
  • projects/vector-embeddings/src/internal.d.ts
    • Adds a declaration file for internal functions used in the project, such as batchedEmbeddings_, similarity_, and others.
  • projects/vector-embeddings/src/main.js
    • Implements the core logic for generating embeddings and performing semantic search using Vertex AI.
  • projects/vector-embeddings/src/tools.js
    • Adds utility functions for calculating dot products, magnitudes, and cosine similarity.
  • projects/vector-embeddings/tsconfig.json
    • Creates a tsconfig.json file to configure the TypeScript compiler options for the project.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Did you know?

The concept of word embeddings, which vector embeddings are based on, gained prominence with the introduction of word2vec in 2013 by a team at Google, led by Tomas Mikolov.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces vector embedding functionality to Google Apps Script using Vertex AI. The code is well-structured and includes a comprehensive README with implementation details and examples. However, there are a few areas that could be improved for clarity and efficiency.

Summary of Findings

  • Missing Error Handling in semanticSearch: The semanticSearch function in examples.js does not handle potential errors during the embedding generation, which could lead to unexpected behavior.
  • Potential Performance Bottleneck in Similarity Calculations: The similarity calculations are performed without caching, which could lead to performance issues when dealing with large datasets.
  • Inconsistent Variable Naming: There are inconsistencies in variable naming conventions across different files (e.g., PROJECT_ID vs. ProjectId).

Merge Readiness

The pull request introduces valuable functionality and is generally well-structured. However, addressing the error handling in semanticSearch and considering caching for similarity calculations would significantly improve the robustness and performance of the code. I am unable to approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

Comment on lines +7 to +24
function semanticSearch(query, corpus) {
// Generate embedding for the query
const queryEmbedding = batchedEmbeddings_([query])[0];

// Create or use existing index
const index = corpus.map((text) => ({
text,
embedding: batchedEmbeddings_([text])[0],
}));

// Calculate similarities
const results = index.map(({ text, embedding }) => ({
text,
similarity: similarity_(embedding, queryEmbedding),
}));

// Sort by similarity (highest first)
return results.sort((a, b) => b.similarity - a.similarity);

Choose a reason for hiding this comment

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

high

The semanticSearch function lacks error handling for the batchedEmbeddings_ calls. If the embedding generation fails, the function will throw an error. Consider adding a try-catch block to handle potential errors and provide more informative feedback to the user. How would you handle this?


const token = ScriptApp.getOAuthToken();

// TODO chunk in instances of 5

Choose a reason for hiding this comment

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

medium

This TODO comment indicates an area for potential optimization. Consider implementing chunking to avoid exceeding API limits and improve performance when processing large amounts of text. How would you implement this chunking?

Comment on lines +38 to +40
function truncate_(text, maxLength) {
return text.slice(0, maxLength) + (text.length > maxLength ? "..." : "");
}

Choose a reason for hiding this comment

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

medium

Consider adding a check for null or undefined text values to prevent errors when truncate_ is called with invalid input. How would you implement this?

@cloudflare-workers-and-pages
Copy link

Deploying apps-script with  Cloudflare Pages  Cloudflare Pages

Latest commit: df60a44
Status: ✅  Deploy successful!
Preview URL: https://3f0ed13c.apps-script.pages.dev
Branch Preview URL: https://feat-embeddings.apps-script.pages.dev

View logs

@jpoehnelt jpoehnelt merged commit 9b6b93a into main Mar 27, 2025
4 of 5 checks passed
@jpoehnelt jpoehnelt deleted the feat/embeddings branch March 28, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants