StructuredRelationship.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.agent.management.rag.structured;
  2. import java.util.List;
  3. public record StructuredRelationship(
  4. RelationshipType type,
  5. String sourceTable,
  6. String sourceColumn,
  7. String targetTable,
  8. String targetColumn,
  9. double confidence,
  10. List<Condition> conditions,
  11. List<String> evidence,
  12. List<String> warnings) {
  13. public StructuredRelationship {
  14. conditions = List.copyOf(conditions == null ? List.of() : conditions);
  15. evidence = List.copyOf(evidence == null ? List.of() : evidence);
  16. warnings = List.copyOf(warnings == null ? List.of() : warnings);
  17. }
  18. public boolean usableForSelection() {
  19. return type != RelationshipType.AMBIGUOUS && confidence >= 0.78;
  20. }
  21. public String id() {
  22. String condition = conditions.stream().map(item -> item.table() + "." + item.column()
  23. + item.operator() + String.valueOf(item.value())).reduce((a, b) -> a + "&" + b).orElse("");
  24. return type + ":" + sourceTable + "." + sourceColumn + "->" + targetTable + "." + targetColumn
  25. + (condition.isBlank() ? "" : "[" + condition + "]");
  26. }
  27. public enum RelationshipType { PHYSICAL_FK, INFERRED, CONDITIONAL, AMBIGUOUS }
  28. public record Condition(String table, String column, String operator, Object value) {}
  29. }