Skip to content

Conversation

@sainikhil1611
Copy link
Collaborator

@sainikhil1611 sainikhil1611 commented Apr 19, 2025

Hugging Face Embedder

Summary by CodeRabbit

  • New Features
    • Added support for generating text and image embeddings locally using Hugging Face models, including the BAAI/bge-m3 and CLIP models.
    • Introduced comprehensive PDF processing, extracting and embedding text, tables, and images from PDF files.
  • Refactor
    • Replaced external API-based embedding generation with local model-based embedding.
    • Simplified error handling and removed API key validation.
  • Chores
    • Added logging for embedding generation and processing results.

@coderabbitai
Copy link

coderabbitai bot commented Apr 19, 2025

Walkthrough

The changes introduce a significant refactor and expansion of embedding generation functionality. The previous Gemini API-based embedding approach in embeddings_converter.py has been replaced with local models using Hugging Face's transformers and SentenceTransformer for text, and CLIP for images. The file processing logic shifts focus exclusively to comprehensive PDF processing, extracting and embedding text, tables, and images locally. Additionally, a new module, hf_embedder.py, is added, providing embedding capabilities for both text and images using the BAAI/bge-m3 model, with robust error handling, logging, and custom exceptions. The codebase now emphasizes local, model-based embedding workflows for various file types.

Changes

File(s) Change Summary
embeddings_converter.py Refactored to use local Hugging Face models for embedding text (SentenceTransformer) and images (CLIP); removed Gemini API usage.
Replaced generic file processing with comprehensive PDF extraction (text, tables, images) and embedding.
Simplified exception handling and removed API key validation.
Updated main() to process a hardcoded PDF and log embedding information.
hf_embedder.py New module for text and image embedding using BAAI/bge-m3 Hugging Face model; includes device management and error handling.
Provides get_text_embedding, get_image_embedding, and process_file functions for various file types with logging.
Defines custom exceptions (EmbeddingError, FileProcessingError) and a testable main() entry point.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant embeddings_converter.py
    participant SentenceTransformer
    participant CLIPModel
    participant pdfplumber

    User->>embeddings_converter.py: main()
    embeddings_converter.py->>pdfplumber: extract_text_from_pdf(pdf_path)
    embeddings_converter.py->>pdfplumber: extract_tables_from_pdf(pdf_path)
    embeddings_converter.py->>pdfplumber: extract_images_from_pdf(pdf_path)
    embeddings_converter.py->>SentenceTransformer: get_hf_text_embedding(text/table)
    embeddings_converter.py->>CLIPModel: get_clip_image_embedding(image)
    embeddings_converter.py-->>User: Log embedding counts and sizes
Loading
sequenceDiagram
    participant User
    participant hf_embedder.py
    participant HuggingFaceModel

    User->>hf_embedder.py: process_file(file_path)
    hf_embedder.py->>HuggingFaceModel: get_text_embedding(text) / get_image_embedding(image)
    hf_embedder.py-->>User: Return embedding or error
Loading

Poem

A rabbit hopped with joyful cheer,
As local models drew embeddings near.
PDFs now yield their secrets wide—
Text, tables, images, all inside!
With Hugging Face and CLIP in tow,
No API keys, just models to show.
Hooray for embeddings, fast and clear! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d5cdfa9 and 2901aee.

📒 Files selected for processing (2)
  • embeddings_converter.py (1 hunks)
  • hf_embedder.py (1 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 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 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.

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