apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: vector-upsert
  labels:
    dagweave.io/catalog-item: vector-upsert
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.2"
    dagweave.io/catalog-category: "AI"
spec:
  entrypoint: upsert
  templates:
    - name: upsert
      inputs:
        parameters:
          # Full Qdrant collection points URL, e.g.
          # https://<host>:6333/collections/<collection>/points.
          - name: endpoint
          # Point id (string or UUID).
          - name: id
          # JSON array of floats — the embedding vector.
          - name: vector-json
          # JSON object of point metadata (Qdrant payload). Defaults to empty object.
          - name: metadata-json
            default: "{}"
          # Name/key of a Kubernetes Secret holding the Qdrant API key (sent as the
          # `api-key` header).
          - name: api-key-secret-name
            default: vector-db-api-key
          - name: api-key-secret-key
            default: api-key
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # badouralix/curl-jq:ubuntu — provides sh, curl and jq.
        image: badouralix/curl-jq@sha256:38362e9b8ef4bd09a88c0db07941e61e0bf0f7240e9f36a3ff2c31ad75546be2
        command: [sh, -c]
        # Values are passed as env vars (below), never interpolated into the shell.
        # jq assembles the Qdrant upsert body {points:[{id, vector, payload}]} with
        # --arg / --argjson so the vector and metadata JSON are embedded verbatim and
        # the id is escaped correctly. Qdrant authenticates via the `api-key` header.
        args:
          - |
            set -eu
            BODY=$(jq -cn \
              --arg id "${POINT_ID}" \
              --argjson vec "${VECTOR}" \
              --argjson payload "${METADATA}" \
              '{points: [{id: $id, vector: $vec, payload: $payload}]}')
            curl -sSf -X PUT "${ENDPOINT}" \
              -H "Content-Type: application/json" \
              -H "api-key: ${API_KEY}" \
              --data-raw "${BODY}"
        env:
          - name: ENDPOINT
            value: "{{inputs.parameters.endpoint}}"
          - name: POINT_ID
            value: "{{inputs.parameters.id}}"
          - name: VECTOR
            value: "{{inputs.parameters.vector-json}}"
          - name: METADATA
            value: "{{inputs.parameters.metadata-json}}"
          - name: API_KEY
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.api-key-secret-name}}"
                key: "{{inputs.parameters.api-key-secret-key}}"
