office-dynamixs-ai/dynamixs-ai-rag/src/main/java/ai/dynamixs/rag/RAGPlugin.java
2025-06-15 12:04:52 +02:00

107 lines
3 KiB
Java

/*
* Imixs-Workflow
*
* Copyright (C) 2001-2020 Imixs Software Solutions GmbH,
* http://www.imixs.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You can receive a copy of the GNU General Public
* License at http://www.gnu.org/licenses/gpl.html
*
* Project:
* https://www.imixs.org
* https://github.com/imixs/imixs-workflow
*
* Contributors:
* Imixs Software Solutions GmbH - Project Management
* Ralph Soika - Software Developer
*/
package ai.dynamixs.rag;
import java.util.List;
import java.util.logging.Logger;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.engine.EventLogService;
import org.imixs.workflow.engine.WorkflowService;
import org.imixs.workflow.engine.plugins.AbstractPlugin;
import org.imixs.workflow.exceptions.PluginException;
import ai.dynamixs.rag.events.RAGEventService;
import jakarta.inject.Inject;
/**
* The RAGIndexPlugin updates the workflow meta data for existing embeddings.
* The plugin can be deactivated with:
* <p>
*
* <pre>
{@code
<rag-index name="DISABLE">
<debug>false</debug>
</rag-index>
}
* </pre>
* <p>
* The tag 'debug' is optional
*
*
* @author rsoika
*
*/
public class RAGPlugin extends AbstractPlugin {
private static final Logger logger = Logger.getLogger(RAGPlugin.class.getName());
@Inject
private WorkflowService workflowService;
@Inject
EventLogService eventLogService;
@Override
public ItemCollection run(ItemCollection workitem, ItemCollection event) throws PluginException {
List<ItemCollection> deleteDefinitions = null;
List<ItemCollection> disableDefinitions = null;
logger.finest("running TaxonomyPlugin");
String workflowResult = event.getItemValueString("workflow.result");
if (workflowResult.contains("<rag-index")) {
deleteDefinitions = workflowService.evalWorkflowResultXML(event, "rag-index",
"DELETE", workitem, false);
disableDefinitions = workflowService.evalWorkflowResultXML(event,
"rag-index",
"DISABLE", workitem, false);
}
// disabled?
if (disableDefinitions != null && disableDefinitions.size() > 0) {
// no op!
return workitem;
}
// delete mode?
if (deleteDefinitions != null && deleteDefinitions.size() > 0) {
eventLogService.createEvent(RAGEventService.EVENTLOG_TOPIC_RAG_EVENT_DELETE, workitem.getUniqueID());
return workitem;
}
// default update meta information
eventLogService.createEvent(RAGEventService.EVENTLOG_TOPIC_RAG_EVENT_UPDATE, workitem.getUniqueID());
return workitem;
}
}