본문 바로가기
개발로그/자동화

n8n Supabase 로 데이터 insert할 때 주의점.

by 그리너리디밸로퍼 2025. 6. 17.

노션 -> 데이터 추출 -> 분할 -> 포멧수정 (DB입력용)  까지 한 결과가 아래 코드라고 가정할 때, 

[
  {
    "page_id": "21475de0-af84-80c0-b4c2-ee34b8653464",
    "chunk": "테스트 청크 데이터",
    "embedding": [0.01, -0.02, 0.003, 0.1, 0.001]  // 짧은 테스트용 배열
  }
]

embadding 항목의 배열을  그대로 insert하려고 하면, 에러가 발생한다 

 

{
  "errorMessage": "Bad request - please check your parameters",
  "errorDescription": "Could not find the '{\n  \"page_id\": \"21475de0-af84-80c0-b4c2-ee34b8653464\",\n  \"chunk\": \"👋  보령 대천의 숨은 명소인 '향천리 냉풍욕장 식당'을 소개하는 정보 보령시 청라면 향천리 청성로 145-1 | 전화문의: 010-2035-7168, 010-2035-7168  📍 ' column of 'embeddings' in the schema cache",
  "errorDetails": {
    "rawErrorMessage": [
      "400 - \"{\\\"code\\\":\\\"PGRST204\\\",\\\"details\\\":null,\\\"hint\\\":null,\\\"message\\\":\\\"Could not find the '{\\\\n  \\\\\\\"page_id\\\\\\\": \\\\\\\"21475de0-af84-80c0-b4c2-ee34b8653464\\\\\\\",\\\\n  \\\\\\\"chunk\\\\\\\": \\\\\\\"👋  보령 대천의 숨은 명소인 '향천리 냉풍욕장 식당'을 소개하는 정보 보령시 청라면 향천리 청성로 145-1 | 전화문의: 010-2035-7168, 010-2035-7168  📍 ' column of 'embeddings' in the schema cache\\\"}\""
    ],
    "httpCode": "400"
  },
  "n8nDetails": {
    "nodeName": "HTTP Request(Supabase)",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "2025. 6. 16. 오후 9:22:06",
    "n8nVersion": "1.95.3 (Cloud)",
    "binaryDataMode": "filesystem",
    "stackTrace": [
      "NodeApiError: Bad request - please check your parameters",
      "    at ExecuteContext.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_openai@4.78.1_encoding@0.1.13_zod@3.24.1_/node_modules/n8n-core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts:1421:10)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at ExecuteContext.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_openai@4.78.1_encoding@0.1.13_zod@3.24.1_/node_modules/n8n-core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts:1707:11)"
    ]
  }

 

이때, HTTP Request 의 Body 부분에서 아래처럼 작성했다. 

{
  "page_id": "{{ $json.pageId }}",
  "chunk": "{{ $json.chunk }}",
  "embedding": {{ $json.embedding }}
}

 

결론은, n8n에서는 이렇게 수정해야 했던 것. 

이유는

배열로 보내는 경우, Supabase API가 JSON을 그대로 벡터로 파싱하기 위해선 정확히 배열 형태여야 하며 문자열이 아니어야 한다. 하지만 n8n의 템플릿 표현식에서는 이게 제대로 처리되지 않는 경우가 있다고 함.

그래서 아래처럼 JSON.stringify()를 사용하여 어찌저찌 성공.

{
  "page_id": "{{ $json.pageId }}",
  "chunk": "{{ $json.chunk }}",
  "embedding": {{ JSON.stringify($json.embedding) }}
}
728x90

댓글