mcolomerc commented on code in PR #250:
URL: https://github.com/apache/flink-agents/pull/250#discussion_r2437011926


##########
integrations/embedding-models/ollama/src/main/java/org/apache/flink/agents/integrations/embeddingmodels/ollama/OllamaEmbeddingModelSetup.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.agents.integrations.embeddingmodels.ollama;
+
+import org.apache.flink.agents.api.embedding.model.BaseEmbeddingModelSetup;
+import org.apache.flink.agents.api.resource.Resource;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceType;
+
+import java.util.List;
+import java.util.function.BiFunction;
+
+/**
+ * An embedding model setup for Ollama powered by the ollama4j client.
+ *
+ * <p>This implementation adapts the generic Flink Agents embedding model 
interface to Ollama's
+ * embedding API. It supports various embedding models available in Ollama 
such as: -
+ * nomic-embed-text (768 dimensions) - mxbai-embed-large (1024 dimensions) - 
all-minilm (384
+ * dimensions) - And other embedding models supported by Ollama
+ *
+ * <p>See also {@link BaseEmbeddingModelSetup} for the common resource 
abstractions and lifecycle.
+ *
+ * <p>Example usage:
+ *
+ * <pre>{@code
+ * public class MyAgent extends Agent {
+ *   // Register the embedding model setup via @EmbeddingModelSetup metadata.
+ *   @EmbeddingModelSetup
+ *   public static ResourceDesc ollama() {
+ *     return 
ResourceDescriptor.Builder.newBuilder(OllamaEmbeddingModelSetup.class.getName())
+ *                 .addInitialArgument("connection", "myConnection") // the 
name of OllamaEmbeddingModelConnection
+ *                 .addInitialArgument("model", "nomic-embed-text") // the 
model name
+ *                 .build();
+ *   }
+ * }
+ * }</pre>
+ */
+public class OllamaEmbeddingModelSetup extends BaseEmbeddingModelSetup {
+
+    public OllamaEmbeddingModelSetup(
+            ResourceDescriptor descriptor, BiFunction<String, ResourceType, 
Resource> getResource) {
+        super(descriptor, getResource);
+    }
+
+    @Override
+    public OllamaEmbeddingModelConnection getConnection() {
+        return (OllamaEmbeddingModelConnection) super.getConnection();
+    }
+
+    /**
+     * Generate embeddings for the given text using the configured Ollama 
model.
+     *
+     * @param text The input text to generate embeddings for
+     * @return An array of floating-point values representing the text 
embeddings
+     */
+    @Override
+    public float[] embed(String text) {
+        return getConnection().embed(text);
+    }
+
+    /**
+     * Generate embeddings for the given text using a specific model.
+     *
+     * @param text The input text to generate embeddings for
+     * @param model The specific embedding model to use
+     * @return An array of floating-point values representing the text 
embeddings
+     */
+    public float[] embed(String text, String model) {

Review Comment:
   added these methods to the parent class, needed to add them as abstract 
methods to the base interface, forcing all embedding model implementations to 
support them. what do you think?



-- 
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]

Reply via email to