{
  "name": "[Sub] Search Schema Docs",
  "settings": {
    "executionOrder": "v1"
  },
  "nodes": [
    {
      "parameters": {
        "content": "## [Sub] Search Schema Docs\n**Purpose:** Semantic-lite search over human-curated table/column descriptions. Lets the agent map business concepts (\"churn\", \"MRR\", \"revenue\") to actual tables without a full vector DB.\n\n**Called by:** main workflow's `search_schema_docs` tool.\n\n**How it works:**\n- Uses Postgres' `pg_trgm` extension (enabled in SETUP.sql) for trigram fuzzy matching against the `public.schema_docs` table.\n- Searches business_description + table_name + column_name.\n- Returns up to 10 doc rows ranked by similarity.\n\n**Setup:** Populate `public.schema_docs` with rows describing your business terminology. Sample INSERT is in SETUP.sql. Returns zero rows if the table is empty \u2014 agent falls back to `list_schema`.\n\n**Upgrade path:** swap this query for pgvector + embeddings when your schema exceeds ~50 tables or has cryptic naming.",
        "height": 360,
        "width": 580,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -420
      ],
      "id": "sticky-sub-docs",
      "name": "README"
    },
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        0
      ],
      "id": "ssd-trigger",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT table_name, column_name, business_description, sample_values\nFROM public.schema_docs\nWHERE business_description ILIKE '%' || $1 || '%'\n   OR table_name ILIKE '%' || $1 || '%'\n   OR column_name ILIKE '%' || $1 || '%'\nORDER BY GREATEST(\n  similarity(business_description, $1),\n  similarity(table_name, $1),\n  similarity(column_name, $1)\n) DESC\nLIMIT 10;",
        "options": {
          "queryReplacement": "={{ $json.term }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        220,
        0
      ],
      "id": "ssd-pg",
      "name": "Search Docs"
    }
  ],
  "connections": {
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Search Docs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}