claudevdm commented on code in PR #33364: URL: https://github.com/apache/beam/pull/33364#discussion_r1887133190
########## sdks/python/apache_beam/ml/rag/embeddings/huggingface.py: ########## @@ -0,0 +1,63 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""RAG-specific embedding implementations using HuggingFace models.""" + +from typing import Optional + +import apache_beam as beam +from apache_beam.ml.inference.base import RunInference +from apache_beam.ml.rag.embeddings.base import create_rag_adapter +from apache_beam.ml.rag.types import Chunk +from apache_beam.ml.transforms.base import EmbeddingsManager +from apache_beam.ml.transforms.base import _TextEmbeddingHandler +from apache_beam.ml.transforms.embeddings.huggingface import SentenceTransformer +from apache_beam.ml.transforms.embeddings.huggingface import _SentenceTransformerModelHandler + + +class HuggingfaceTextEmbeddings(EmbeddingsManager): + def __init__( + self, model_name: str, *, max_seq_length: Optional[int] = None, **kwargs): + """Utilizes huggingface SentenceTransformer embeddings for RAG pipeline. + + Args: + model_name: Name of the sentence-transformers model to use + max_seq_length: Maximum sequence length for the model + **kwargs: Additional arguments including ModelHandlers arguments Review Comment: I mirrored the arguments from the regular SentenceTransformerEmbeddings [1] excluding the columns argument. What do you mean by link to the base class? https://github.com/apache/beam/blob/4f70ca1be201b8c80e198c405c09ff6c656772c9/sdks/python/apache_beam/ml/transforms/embeddings/huggingface.py#L110 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
