ONNX Model Zoo

rokeya71/granite-embedding-30m-english-optimum-q8

By rokeya71 · ↓ 0 · ♥ 0 · Updated 2025-01-01

What's in this repo

This page lists the files in rokeya71/granite-embedding-30m-english-optimum-q8, including model.onnx.

  • 1 ONNX models (.onnx files)
  • 9 files, including 5 .json, 1 .md, 1 .txt, 1 .onnx
  • Last updated 2025-01-01

ONNX files

File Size Download
model.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

Converted and quantized.

Custom Embedding Class for Optimum ONNX Runtime

This document provides the implementation of a custom embedding class designed to work with the Optimum ONNX Runtime model.

from typing import List
from llama_index.embeddings.huggingface_optimum import OptimumEmbedding
import asyncio

class CustomEmbedding:
    def __init__(self, folder_name: str):
        """Initialize the embedding model."""
        self.embed_model = OptimumEmbedding(folder_name=folder_name)

    async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
        """Asynchronously embed a list of documents."""
        loop = asyncio.get_event_loop()
        return await loop.run_in_executor(None, self.embed_documents, texts)

    async def aembed_query(self, text: str) -> List[float]:
        """Asynchronously embed a single query."""
        loop = asyncio.get_event_loop()
        return await loop.run_in_executor(None, self.embed_query, text)

    def embed_documents(self, texts: List[str]) -> List[List[float]]:
        """Embed a list of documents."""
        return [self.embed_model.get_text_embedding(text) for text in texts]

    def embed_query(self, text: str) -> List[float]:
        """Embed a single query."""
        return self.embed_model.get_text_embedding(text)

# Example Usage
custom_embeddings = CustomEmbedding(folder_name="./optimum_model")

Key Features

  1. Initialization:

    • The CustomEmbedding class initializes the OptimumEmbedding instance with the specified folder_name for the preloaded model.
  2. Asynchronous Methods:

    • aembed_documents(texts: List[str]): Asynchronously embeds a list of documents and returns their embeddings.
    • aembed_query(text: str): Asynchronously embeds a single query and returns its embedding.
  3. Synchronous Methods:

    • embed_documents(texts: List[str]): Embeds a list of documents and returns their embeddings.
    • embed_query(text: str): Embeds a single query and returns its embedding.

Usage

  • Folder Name: Replace "./optimum_model" with the path to your locally stored Optimum ONNX Runtime model.

  • Example:

    # Embed a single query
    query_embedding = custom_embeddings.embed_query("Hello World!")
    
    # Embed multiple documents
    document_embeddings = custom_embeddings.embed_documents(["Document 1", "Document 2"])
    

Model info

onnx roberta license:apache-2.0 region:us
↓ 0 ♥ 0

Created: 2025-01-01

Updated: 2025-01-01

View on Hugging Face

Files (9)

.gitattributes
README.md
config.json
merges.txt
model.onnx ONNX
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.json

Related models