itsayushpandey commented on code in PR #32018: URL: https://github.com/apache/beam/pull/32018#discussion_r1698895682
########## examples/notebooks/beam-ml/rag_usecase/opensearch_connector.py: ########## @@ -0,0 +1,383 @@ +# +# 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. +# + +from __future__ import absolute_import + +import logging + +import apache_beam as beam + +from apache_beam.transforms import DoFn +from apache_beam.transforms import PTransform +from apache_beam.transforms import Reshuffle +from apache_beam import coders + + +import typing +from opensearchpy import OpenSearch + +import os +from dotenv import load_dotenv + + +load_dotenv() + + +# Set the logging level to reduce verbose information +import logging + +logging.root.setLevel(logging.INFO) +logger = logging.getLogger(__name__) + + +__all__ = ['InsertDocInOpenSearch','InsertEmbeddingInOpenSearch'] + + + + +"""This module implements IO classes to read document in Opensearch. + + +Insert Doc in OpenSearch: +----------------- +:class:`InsertDocInOpenSearch` is a ``PTransform`` that writes key and values to a +configured sink, and the write is conducted through a Opensearch pipeline. + +The ptransform works by getting the first and second elements from the input, +this means that inputs like `[k,v]` or `(k,v)` are valid. + +Example usage:: + + pipeline | InsertDocInOpenSearch(host='localhost', + port=6379, + batch_size=100) + + +No backward compatibility guarantees. Everything in this module is experimental. +""" +class InsertDocInOpenSearch(PTransform): + """InsertDocInOpensearch is a ``PTransform`` that writes a ``PCollection`` of + key, value tuple or 2-element array into a Opensearch server. + """ + + def __init__(self, + host:str, + port:int, + username:str, + password:str, + batch_size:int=100 + ): + """ + + Args: + host (str, ValueProvider): The Opensearch host + port (int, ValueProvider): The Opensearch port + batch_size(int, ValueProvider): Number of key, values pairs to write at once Review Comment: @jrmccluskey I have committed the working code, but clean up is still pending. I should have marked this PR as draft. I'll cleanup the code now but can show the working output only after previous PR is merged as I will need to update the code in beam_rag_notebook.ipynb. -- 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: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org