TrustGraphGet Started

Flow Classes (TrustGraph)

Templates or blueprints for TrustGraph flows, defining reusable processing pipelines that can be instantiated with different configurations.

TrustGraph Concepts

Flow Classes are reusable templates for TrustGraph flows, similar to classes in object-oriented programming, allowing you to define processing pipelines once and instantiate them multiple times with different configurations.

Defining a Flow Class

// Define a reusable flow class
const DocumentIngestionClass = await trustgraph.flowClasses.define({
  name: "DocumentIngestion",
  description: "Standard document ingestion pipeline",
  parameters: {
    documentType: {
      type: "string",
      enum: ["pdf", "docx", "txt", "html"],
      required: true
    },
    extractionModel: {
      type: "string",
      default: "en_core_web_lg"
    },
    minConfidence: {
      type: "number",
      default: 0.7,
      min: 0,
      max: 1
    }
  },
  stages: [
    {
      name: "extract-text",
      processor: "text-extractor",
      config: {
        type: "{{documentType}}"  // Parameter interpolation
      }
    },
    {
      name: "extract-entities",
      processor: "ner-extractor",
      config: {
        model: "{{extractionModel}}",
        minConfidence: "{{minConfidence}}"
      }
    },
    {
      name: "build-graph",
      processor: "graph-builder"
    }
  ]
});

Instantiating Flows

// Create flow instances from class
const pdfFlow = await DocumentIngestionClass.instantiate({
  documentType: "pdf",
  extractionModel: "en_core_web_lg",
  minConfidence: 0.8
});

const htmlFlow = await DocumentIngestionClass.instantiate({
  documentType: "html",
  extractionModel: "en_core_web_sm",  // Lighter model for HTML
  minConfidence: 0.6
});

// Use the flows
await pdfFlow.process({ source: "document.pdf" });
await htmlFlow.process({ source: "webpage.html" });

Built-in Flow Classes

TrustGraph provides standard flow classes:

// Pre-built flow classes
const classes = [
  "StandardIngestion",      // General document ingestion
  "EntityExtraction",       // Just entity extraction
  "RelationshipExtraction", // Just relationship extraction
  "GraphRAGQuery",         // Standard GraphRAG query
  "VectorSearch",          // Simple vector search
  "GraphUpdate",           // Graph modification
  "DataExport"             // Export data
];

// Use built-in class
const ingestion = await trustgraph.flowClasses.get("StandardIngestion");
const flow = await ingestion.instantiate({
  source: "documents/",
  entityTypes: ["PERSON", "ORG", "PRODUCT"]
});

Benefits

  • Reusability: Define once, use many times
  • Consistency: Standard pipelines across projects
  • Maintainability: Update class, all instances benefit
  • Sharing: Share flow classes across team

See Also

Examples

  • DocumentIngestionFlowClass: Template for ingesting any document type
  • EntityExtractionFlowClass: Reusable NER pipeline

Related Terms

Learn More