Warning in type list in output

Hi @victor_palacios,

I saw your presentation regarding python extension and I was wondering if you can give me a hand.

I am dealing with a simple warning but I still wondering way is happening.

In the output port I am having 2 string columns and one list column.

In the configure module I declare the list as follows:

def configure(self, config_context, input_table_schema, input_spec: ISK_GenericPortObjectSpec) → list:
# Define output schema
types= [knext.string(), knext.string(), knext.list_(knext.string())]
names= [“Document”, “Chunk Name”, “Embedded Text”]
schema = knext.Schema(types, names)

    serialized_schema = json.dumps(schema.serialize())
    spec_output = ISK_GenericPortObjectSpec(spec_data=serialized_schema, schema=schema)
    
    return [spec_output, schema]

In the execute module I return the knime.table as per instructions in the guide:

return [output_port_object, knext.Table.from_pandas(table_output)]

however, I still receiving a warning after execution:

I wish, I could sent you all the code, but it is for my company so I cannot show all of it. However, if you can help me to clear the warning it will be much appreciated. Perhaps it is a KNIME bug???

Thanks in advance,

AG.

I will reply this myself:

The configuration need to match in the configure and execute modules:

def configure(self, config_context, input_table_schema, input_spec: ISK_GenericPortObjectSpec) -> list:
        # Define output schema
        types = [knext.string(), knext.string(), knext.list_(knext.double())]
        names = ["Document", "Chunk Name", "Embedded Text"]
        schema = knext.Schema(types, names)
        
        serialized_schema = json.dumps(schema.serialize())
        spec_output = ISK_GenericPortObjectSpec(spec_data=serialized_schema, schema=schema)
        
        return [spec_output, schema]
def execute(self, exec_context: knext.ExecutionContext, context_table: knext.Table, input_port: ISK_GenericPortObject) -> list:
        # Deserialize data from the custom port
        serialized_data = input_port._model
        deserialized_data = pickle.loads(serialized_data)
        if not isinstance(deserialized_data, pd.DataFrame):
            raise ValueError(f"Expected deserialized data to be a pandas DataFrame, but got {type(deserialized_data)}")
        
        # Convert context table to pandas DataFrame
        context_df = context_table.to_pandas()
        
        # Ensure required columns are present in context data
        required_columns = ["Document", "Chunk Name", "Text"]
        for col in required_columns:
            if col not in context_df.columns:
                raise ValueError(f"The '{col}' column is missing in the context data.")
        
        # Concatenate the context data to the deserialized data
        combined_df = pd.concat([context_df, deserialized_data], ignore_index=True)
        
        # Generate embeddings
        embeddings = self.semantic_search(combined_df, self.model_path)
        
        # Create the output DataFrame
        output_df = pd.DataFrame({
            "Document": combined_df["Document"],
            "Chunk Name": combined_df["Chunk Name"],
            "Embedded Text": embeddings.tolist()
        })
        
        # Serialize the output DataFrame
        types = [knext.string(), knext.string(), knext.list_(knext.double())]  
        names = ["Document", "Chunk Name", "Embedded Text"]
        schema = knext.Schema(types, names)
        serialized_schema = json.dumps(schema.serialize())
        spec = ISK_GenericPortObjectSpec(spec_data=serialized_schema, schema=schema)
        
        serialized_output_data = pickle.dumps(output_df)
        output_port_object = ISK_GenericPortObject(spec, serialized_output_data)
        table_output = output_df
        
        # Return both the custom port object and the KNIME table
        return [output_port_object, knext.Table.from_pandas(table_output)]

Just in case have similar problems with this.

Hi @VAGR_ISK,

I’m glad you found the solution and thanks for sharing it here :slight_smile: .

Best,
Keerthan

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.