Skip to content

Commit

Permalink
SAS-365: change the Type parameter to Entity parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tswarmerdam-mx committed Apr 30, 2024
1 parent dc44d97 commit 2c79897
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Binary file modified OpenAI Showcase App.mpr
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

package pgvectorknowledgebase.actions;

import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaObject;
import com.mendix.webui.CustomJavaAction;
import pgvectorknowledgebase.impl.ChunkUtils;
import pgvectorknowledgebase.impl.MxLogger;
Expand All @@ -32,14 +34,14 @@ public class ChunkList_RetrieveNearestNeighbors_SetAssociation extends CustomJav
private IMendixObject __DatabaseConfiguration;
private pgvectorknowledgebase.proxies.DatabaseConfiguration DatabaseConfiguration;
private java.lang.String KnowledgeBaseName;
private IMendixObject TargetChunk;
private java.lang.String TargetChunk;
private java.lang.String Vector;
private java.util.List<IMendixObject> __LabelList;
private java.util.List<pgvectorknowledgebase.proxies.Label> LabelList;
private java.lang.Long MaxNumberOfResults;
private java.math.BigDecimal MinimumSimilarity;

public ChunkList_RetrieveNearestNeighbors_SetAssociation(IContext context, IMendixObject DatabaseConfiguration, java.lang.String KnowledgeBaseName, IMendixObject TargetChunk, java.lang.String Vector, java.util.List<IMendixObject> LabelList, java.lang.Long MaxNumberOfResults, java.math.BigDecimal MinimumSimilarity)
public ChunkList_RetrieveNearestNeighbors_SetAssociation(IContext context, IMendixObject DatabaseConfiguration, java.lang.String KnowledgeBaseName, java.lang.String TargetChunk, java.lang.String Vector, java.util.List<IMendixObject> LabelList, java.lang.Long MaxNumberOfResults, java.math.BigDecimal MinimumSimilarity)
{
super(context);
this.__DatabaseConfiguration = DatabaseConfiguration;
Expand All @@ -65,14 +67,15 @@ public java.util.List<IMendixObject> executeAction() throws Exception
// BEGIN USER CODE

try {
ChunkUtils.validateTargetChunk(this.TargetChunk);
IMetaObject targetChunk = Core.getMetaObject(TargetChunk);
ChunkUtils.validateTargetChunk(targetChunk);

// call a microflow to retrieve chunks
java.util.List<Chunk> chunkList = pgvectorknowledgebase.proxies.microflows.Microflows.chunkList_RetrieveNearestNeighbors(
getContext(), DatabaseConfiguration, KnowledgeBaseName, Vector, MinimumSimilarity, MaxNumberOfResults, LabelList);

//map to target chunks to return
return ChunkUtils.getTargetChunkList(getContext(), chunkList, TargetChunk, LOGGER);
return ChunkUtils.getTargetChunkList(getContext(), chunkList, targetChunk, LOGGER);

} catch (Exception e) {
LOGGER.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

package pgvectorknowledgebase.actions;

import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaObject;
import com.mendix.webui.CustomJavaAction;
import pgvectorknowledgebase.impl.ChunkUtils;
import pgvectorknowledgebase.impl.MxLogger;
Expand All @@ -32,13 +34,13 @@ public class ChunkList_Retrieve_SetAssociation extends CustomJavaAction<java.uti
private IMendixObject __DatabaseConfiguration;
private pgvectorknowledgebase.proxies.DatabaseConfiguration DatabaseConfiguration;
private java.lang.String KnowledgeBaseName;
private IMendixObject TargetChunk;
private java.lang.String TargetChunk;
private java.util.List<IMendixObject> __LabelList;
private java.util.List<pgvectorknowledgebase.proxies.Label> LabelList;
private java.lang.Long MaxNumberOfResults;
private java.lang.Long Offset;

public ChunkList_Retrieve_SetAssociation(IContext context, IMendixObject DatabaseConfiguration, java.lang.String KnowledgeBaseName, IMendixObject TargetChunk, java.util.List<IMendixObject> LabelList, java.lang.Long MaxNumberOfResults, java.lang.Long Offset)
public ChunkList_Retrieve_SetAssociation(IContext context, IMendixObject DatabaseConfiguration, java.lang.String KnowledgeBaseName, java.lang.String TargetChunk, java.util.List<IMendixObject> LabelList, java.lang.Long MaxNumberOfResults, java.lang.Long Offset)
{
super(context);
this.__DatabaseConfiguration = DatabaseConfiguration;
Expand All @@ -63,15 +65,15 @@ public java.util.List<IMendixObject> executeAction() throws Exception
// BEGIN USER CODE

try {

ChunkUtils.validateTargetChunk(TargetChunk);
IMetaObject targetChunk = Core.getMetaObject(TargetChunk);
ChunkUtils.validateTargetChunk(targetChunk);

// call a microflow to retrieve chunks
java.util.List<Chunk> chunkList = pgvectorknowledgebase.proxies.microflows.Microflows.chunkList_Retrieve(
getContext(), DatabaseConfiguration, KnowledgeBaseName, MaxNumberOfResults, LabelList, Offset);

//map to target chunks to return
return ChunkUtils.getTargetChunkList(getContext(), chunkList, TargetChunk, LOGGER);
return ChunkUtils.getTargetChunkList(getContext(), chunkList, targetChunk, LOGGER);

} catch (Exception e) {
LOGGER.error(e.getMessage());
Expand Down
12 changes: 6 additions & 6 deletions javasource/pgvectorknowledgebase/impl/ChunkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaAssociation;
import com.mendix.systemwideinterfaces.core.meta.IMetaObject;

import communitycommons.ORM;
import pgvectorknowledgebase.proxies.Chunk;

public class ChunkUtils {


public static void validateTargetChunk(IMendixObject TargetChunk) throws Exception {
public static void validateTargetChunk(IMetaObject TargetChunk) throws Exception {
// verify target chunk on non-null, subclass of chunk,
requireNonNull(TargetChunk, "Target Chunk must be specified");
if (! TargetChunk.getMetaObject().isSubClassOf("PgVectorKnowledgeBase.Chunk")){
if (! TargetChunk.isSubClassOf("PgVectorKnowledgeBase.Chunk")){
throw new Exception("Target Chunk must be a specialization of PgVectorKnowledgeBase.Chunk");
}
};
Expand All @@ -28,14 +29,14 @@ public static void validateTargetChunk(IMendixObject TargetChunk) throws Excepti


public static java.util.List<IMendixObject> getTargetChunkList(
IContext context, java.util.List<Chunk> chunkList, IMendixObject targetChunk, MxLogger LOGGER) {
IContext context, java.util.List<Chunk> chunkList, IMetaObject targetChunk, MxLogger LOGGER) {
// create list to return
java.util.List<IMendixObject> targetChunkList = new ArrayList<IMendixObject>();

// per chunk create a TargetChunk (custom specialization)
chunkList.forEach(c -> {
// - instantiate Target Chunk (custom specialization)
IMendixObject targetChunkSpecialization = Core.instantiate(context, targetChunk.getMetaObject().getName());
IMendixObject targetChunkSpecialization = Core.instantiate(context, targetChunk.getName());
// copy values from Chunk to Target Chunk (custom specialization)
ORM.cloneObject(context, c.getMendixObject(), targetChunkSpecialization, true);
try {
Expand All @@ -49,7 +50,6 @@ public static java.util.List<IMendixObject> getTargetChunkList(

// find matching association based on meta object name
Long assocationsSetCount= targetChunk
.getMetaObject()
.getMetaAssociationsParent()
.stream()
.filter(a -> assocationMatchesTarget(a, targetObject))
Expand All @@ -59,7 +59,7 @@ public static java.util.List<IMendixObject> getTargetChunkList(
// set association if found, otherwise log a warning
if (assocationsSetCount == 0){
LOGGER.warn("No eligible association found for target object " + targetObject.getMetaObject().getName()
+ " on entity " + targetChunk.getMetaObject().getName());
+ " on entity " + targetChunk.getName());
}

} catch (Exception e) {
Expand Down

0 comments on commit 2c79897

Please sign in to comment.