001/** 002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.gnu.org/licenses/lgpl-3.0.txt 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package dev.tinyflow.core.node; 017 018import com.agentsflex.core.chain.Chain; 019import com.agentsflex.core.chain.node.BaseNode; 020import com.agentsflex.core.document.Document; 021import com.agentsflex.core.util.Maps; 022import dev.tinyflow.core.knowledge.Knowledge; 023 024import java.util.List; 025import java.util.Map; 026 027public class KnowledgeNode extends BaseNode { 028 029 private Object knowledgeId; 030 private Knowledge knowledge; 031 private int queryCount; 032 033 public Object getKnowledgeId() { 034 return knowledgeId; 035 } 036 037 public void setKnowledgeId(Object knowledgeId) { 038 this.knowledgeId = knowledgeId; 039 } 040 041 public int getQueryCount() { 042 return queryCount; 043 } 044 045 public void setQueryCount(int queryCount) { 046 this.queryCount = queryCount; 047 } 048 049 public Knowledge getKnowledge() { 050 return knowledge; 051 } 052 053 public void setKnowledge(Knowledge knowledge) { 054 this.knowledge = knowledge; 055 } 056 057 @Override 058 protected Map<String, Object> execute(Chain chain) { 059 Map<String, Object> argsMap = getParameters(chain); 060 061 String query = (String) argsMap.get("query"); 062 List<Document> result = knowledge.search(query, 10); 063 064 return Maps.of("documents", result); 065 } 066 067 @Override 068 public String toString() { 069 return "KnowledgeNode{" + 070 "knowledgeId=" + knowledgeId + 071 ", queryCount=" + queryCount + 072 ", description='" + description + '\'' + 073 ", parameters=" + parameters + 074 ", outputDefs=" + outputDefs + 075 ", id='" + id + '\'' + 076 ", name='" + name + '\'' + 077 ", async=" + async + 078 ", inwardEdges=" + inwardEdges + 079 ", outwardEdges=" + outwardEdges + 080 ", condition=" + condition + 081 ", memory=" + memory + 082 ", nodeStatus=" + nodeStatus + 083 '}'; 084 } 085}