
# Procurize.AI REST API 레퍼런스

**API 토큰을 사용해 지식 베이스(문서, 설문지, RAG 및 보고서)에 프로그래밍 방식으로 접근합니다.**

> **대상:** Procurize.AI API v1  
> **인증:** `X-API-Key` 헤더를 통한 API 키 (토큰 관리는 [API 토큰](/api-tokens/) 참고)  
> **기본 URL:** `https://api.procurize.com`

## 개요

Procurize.AI REST API는 플랫폼 핵심 기능에 프로그래밍 방식으로 접근할 수 있게 해줍니다. 이를 통해 내부 시스템과 Procurize.AI를 통합하고, 지식 베이스 관리를 자동화하며, 맞춤형 워크플로를 구축할 수 있습니다.

**지원 모듈 (토큰 인증):**

- [**RagArticle**](#ragarticle) – 문서 관리
- [**RagFaq**](#ragfaq) – FAQ 항목 관리
- [**RagQuery**](#ragquery) – RAG 질의 실행

## 인증

모든 인증이 필요한 엔드포인트는 요청 헤더에 API 토큰을 전달해야 합니다.

| 헤더 | 값 |
|------|----|
| `X-API-Key` | `<YOUR_API_TOKEN>` |

**예시:**
```bash
curl -X GET "https://api.procurize.com/v1/..." \
  -H "X-API-Key: your-api-token-here"
```

> 💡 토큰은 조직에 바인딩되어 있으므로 요청에 조직 ID를 별도로 지정할 필요가 없습니다.

## 기본 URL

모든 REST API 엔드포인트는 다음 주소에서 제공됩니다:
```
https://api.procurize.com
```

## 오류 처리

API는 표준 HTTP 상태 코드를 사용합니다.

| 코드 | 의미 |
|------|------|
| `200 OK` | 요청 성공 |
| `201 Created` | 리소스가 성공적으로 생성됨 |
| `204 No Content` | 요청 성공, 응답 본문 없음 |
| `400 Bad Request` | 잘못된 매개변수 또는 형식 오류 |
| `401 Unauthorized` | API 토큰 누락 또는 유효하지 않음 |
| `403 Forbidden` | 토큰에 해당 작업 권한이 없음 |
| `404 Not Found` | 리소스를 찾을 수 없음 |
| `500 Internal Server Error` | 서버 내부 오류 |

오류 응답에는 기계가 읽을 수 있는 오류 코드와 사람이 읽을 수 있는 메시지가 포함됩니다.

## 모듈 레퍼런스

### RagArticle

#### GET /questionnaire/rag/articles/summary

**요약:** 홈 페이지 요약

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| proj | query | string (uuid) | 아니오 | 프로젝트 ID. |

**응답 (200):**
```json
{
  "active": 5
}
```

---

#### GET /questionnaire/rag/articles/total

**요약:** 문서 수

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| q | query | string | 아니오 | 문서 이름 또는 코드 필터. |
| state | query | array | 아니오 | 상태 필터. |
| project | query | array | 아니오 | 프로젝트 필터. |
| type | query | array | 아니오 | 문서 유형 필터. |

**응답 (200):**
```json
42
```

---

#### GET /questionnaire/rag/articles/list

**요약:** 문서 목록 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| q | query | string | 아니오 | 문서 이름 또는 코드 필터. |
| state | query | array | 아니오 | 상태 필터. |
| project | query | array | 아니오 | 프로젝트 필터. |
| type | query | array | 아니오 | 문서 유형 필터. |
| s | query | string | 아니오 | 정렬 필드. |
| asc | query | boolean | 아니오 | 오름차순 정렬. |
| ps | query | integer (int32) | 아니오 | 페이지 크기. |
| p | query | integer (int32) | 아니오 | 1부터 시작하는 페이지 번호. |

**응답 (200):**
```json
{
  "paging": {
    "pageNumber": 1,
    "pageSize": 10,
    "total": 42,
    "totalPages": 5
  },
  "items": [
    {
      "code": "ART-001",
      "org": "00000000-0000-0000-0000-000000000000",
      "id": "00000000-0000-0000-0000-000000000000",
      "name": "Article Title",
      "description": "Article description",
      "documentTypes": [
        {
          "id": "00000000-0000-0000-0000-000000000000",
          "name": "Type Name",
          "plural": "Type Names",
          "count": 5
        }
      ],
      "size": 150,
      "revision": {
        "id": "00000000-0000-0000-0000-000000000000",
        "collectionId": "00000000-0000-0000-0000-000000000000",
        "rev": 3,
        "date": "2025-01-15T10:30:00Z",
        "author": {
          "id": "user123",
          "name": "John Doe",
          "email": "john.doe@example.com",
          "login": "johndoe",
          "ra": true
        },
        "authorName": "John Doe",
        "analysisSummary": {
          "id": "00000000-0000-0000-0000-000000000000",
          "initiator": {
            "id": "user123",
            "name": "John Doe",
            "email": "john.doe@example.com",
            "login": "johndoe",
            "ra": true
          },
          "created": "2025-01-15T10:30:00Z",
          "state": "Completed",
          "stateDate": "2025-01-15T10:35:00Z",
          "stateDetails": "Analysis completed successfully",
          "operationId": "op-12345"
        }
      },
      "type": "Article",
      "state": "Active",
      "projects": [
        "00000000-0000-0000-0000-000000000000"
      ],
      "items": [
        "00000000-0000-0000-0000-000000000000"
      ],
      "isShared": false
    }
  ]
}
```

---

#### POST /questionnaire/rag/file-to-md

**요약:** 파일에서 Markdown 콘텐츠 반환

**요청 본문 (multipart/form-data):**
```json
{
  "url": "https://example.com/file.pdf",
  "file": "binary"
}
```

**응답 (200):**
```json
"Markdown content from file"
```

---

#### POST /questionnaire/rag/article/create

**요약:** 문서 생성

**요청 본문 (multipart/form-data):**
```json
{
  "code": "ART-001",
  "name": "Article Title",
  "description": "Article description",
  "content": "# Article Content\n\nThis is the article content.",
  "url": "https://example.com/file.pdf",
  "file": "binary"
}
```

**응답 (200):**
```json
{
  "code": "ART-001",
  "org": "00000000-0000-0000-0000-000000000000",
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "Article Title",
  "description": "Article description",
  "documentTypes": null,
  "size": 150,
  "revision": null,
  "type": "Article",
  "state": "Active",
  "projects": null,
  "items": null,
  "isShared": false
}
```

---

#### GET /questionnaire/rag/article/check

**요약:** 문서 존재 여부 확인

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |

**응답 (200):**
```json
true
```

---

#### GET /questionnaire/rag/article-info

**요약:** 코드로 문서 정보 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |

**응답 (200):**
```json
{
  "code": "ART-001",
  "org": "00000000-0000-0000-0000-000000000000",
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "Article Title",
  "description": "Article description",
  "documentTypes": null,
  "size": 150,
  "revision": null,
  "type": "Article",
  "state": "Active",
  "projects": null,
  "items": null,
  "isShared": false
}
```

---

#### GET /questionnaire/rag/article

**요약:** 코드로 문서 콘텐츠 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |
| format | query | string | 아니오 | `true`이면 HTML 콘텐츠를 반환하고, 그렇지 않으면 Markdown 형식으로 반환합니다. |
| split | query | boolean | 아니오 | `true`이면 RAG 요소별로 분리된 콘텐츠를 반환합니다. |
| css | query | boolean | 아니오 | `true`이면 CSS가 포함된 HTML/PDF 콘텐츠를 반환합니다. |

**응답 (200):**
```json
"# Article Title\n\nThis is the article content in Markdown format."
```

#### POST /questionnaire/rag/article

**요약:** 문서 메타데이터 업데이트

**요청 본문:**
```json
{
  "code": "ART-001",
  "name": "Updated Article Title",
  "description": "Updated description",
  "projects": [
    "00000000-0000-0000-0000-000000000000"
  ],
  "documentTypes": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "name": "Type Name",
      "plural": "Type Names"
    }
  ],
  "isShared": true,
  "state": "Active"
}
```

**응답 (200):**
```json
{}
```

#### DELETE /questionnaire/rag/article

**요약:** 문서 삭제

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |

---

#### GET /questionnaire/rag/article/pdf

**요약:** 코드로 PDF 형식 문서 가져오기

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |

**응답 (200):**
```json
(pdf binary)
```

---

#### GET /questionnaire/rag/article/content

**요약:** 문서 콘텐츠 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |

**응답 (200):**
```json
{
  "content": "# Article Title\n\nContent here."
}
```

---

#### POST /questionnaire/rag/article/content

**요약:** 문서 콘텐츠 업데이트

**요청 본문 (multipart/form-data):**
```json
{
  "code": "ART-001",
  "content": "# Updated Content",
  "file": "binary"
}
```

---

#### POST /questionnaire/rag/plural

**요약:** 명사의 복수형 반환

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| noun | query | string | 아니오 | 복수형으로 변환할 명사. |

**응답 (200):**
```json
{
  "plural": "Articles"
}
```

---

#### POST /questionnaire/rag/article/find-types

**요약:** AI로 문서 분석 후 유형 반환

**요청 본문 (multipart/form-data):**
```json
{
  "code": "ART-001",
  "content": "# Article Content"
}
```

**응답 (200):**
```json
[
  {
    "plural": "Types"
  }
]
```

---

#### POST /questionnaire/rag/article/format-with-ai

**요약:** AI로 문서 콘텐츠 포맷팅

**요청 본문 (multipart/form-data):**
```json
{
  "code": "ART-001",
  "content": "# Article Content"
}
```

**응답 (200):**
```json
{
  "formattedContent": "# Formatted Article Content"
}
```

---

#### POST /questionnaire/rag/article/improve-on-suggestions

**요약:** 제안 기반 문서 개선

**요청 본문 (multipart/form-data):**
```json
{
  "suggestions": [
    {
      "sectionTitle": "Introduction",
      "suggestion": "Add more details here."
    }
  ],
  "code": "ART-001",
  "content": "# Article Content"
}
```

**응답 (200):**
```json
{
  "improvedContent": "# Improved Content"
}
```

---

#### GET /questionnaire/rag/article/parts

**요약:** 문서 파트 목록 반환

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | query | array | 예 | 문서 파트 ID 목록. |

**응답 (200):**
```json
[
  {
    "id": "00000000-0000-0000-0000-000000000000",
    "code": "part-1",
    "title": "Introduction",
    "orderNumber": 1,
    "content": "Introduction content."
  }
]
```

---

#### GET /questionnaire/rag/article/revisions

**요약:** 문서 리비전 목록 반환

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |

**응답 (200):**
```json
[
  {
    "id": "00000000-0000-0000-0000-000000000000",
    "collectionId": "00000000-0000-0000-0000-000000000000",
    "rev": 1,
    "date": "2025-01-15T10:30:00Z",
    "author": {
      "id": "user123",
      "name": "John Doe",
      "email": "john.doe@example.com",
      "login": "johndoe",
      "ra": true
    },
    "authorName": "John Doe",
    "analysisSummary": {
      "id": "00000000-0000-0000-0000-000000000000",
      "initiator": {
        "id": "user123",
        "name": "John Doe",
        "email": "john.doe@example.com",
        "login": "johndoe",
        "ra": true
      },
      "created": "2025-01-15T10:30:00Z",
      "state": "Completed",
      "stateDate": "2025-01-15T10:35:00Z",
      "stateDetails": "Analysis completed",
      "operationId": "op-12345"
    }
  }
]
```

---

#### GET /questionnaire/rag/article/revisions/info/{id}

**요약:** 문서 리비전 정보 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | path | string (uuid) | 예 | 리비전 ID. |

**응답 (200):**
```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "collectionId": "00000000-0000-0000-0000-000000000000",
  "rev": 1,
  "date": "2025-01-15T10:30:00Z",
  "author": {
    "id": "user123",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "login": "johndoe",
    "ra": true
  },
  "authorName": "John Doe",
  "analysisSummary": {
    "id": "00000000-0000-0000-0000-000000000000",
    "initiator": {
      "id": "user123",
      "name": "John Doe",
      "email": "john.doe@example.com",
      "login": "johndoe",
      "ra": true
    },
    "created": "2025-01-15T10:30:00Z",
    "state": "Completed",
    "stateDate": "2025-01-15T10:35:00Z",
    "stateDetails": "Analysis completed",
    "operationId": "op-12345"
  }
}
```

---

#### GET /questionnaire/rag/article/revisions/{id}

**요약:** 문서 리비전 콘텐츠 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | path | string (uuid) | 예 | 리비전 ID. |

**응답 (200):**
```json
"# Article Revision Content\n\nPrevious version."
```

---

#### GET /questionnaire/rag/article/analyze

**요약:** AI로 문서 콘텐츠 분석

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 문서 코드. |
| rev | query | integer (int32) | 아니오 | 리비전 번호. |
| force | query | boolean | 아니오 | 기존 미완료 분석 결과를 삭제하고 새 분석을 강제로 생성합니다. |

**응답 (200):**
```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "initiator": {
    "id": "user123",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "login": "johndoe",
    "ra": true
  },
  "created": "2025-01-15T10:30:00Z",
  "state": "Completed",
  "stateDate": "2025-01-15T10:35:00Z",
  "stateDetails": "Analysis completed",
  "operationId": "op-12345"
}
```

---

#### GET /questionnaire/rag/article/analyze/{id}

**요약:** 문서 분석 결과 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | path | string (uuid) | 예 | 분석 ID. |

**응답 (200):**
```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "initiator": {
    "id": "user123",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "login": "johndoe",
    "ra": true
  },
  "created": "2025-01-15T10:30:00Z",
  "state": "Completed",
  "stateDate": "2025-01-15T10:35:00Z",
  "stateDetails": "Analysis completed",
  "operationId": "op-12345",
  "fragments": [
    "fragment-1",
    "fragment-2"
  ],
  "ownInconcies": "Own inconsistencies found",
  "ragInconcies": "RAG inconsistencies found",
  "proposals": "Improvement proposals"
}
```

---

#### GET /questionnaire/rag/messages/list

**요약:** 모든 메시지 목록

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | query | string (uuid) | 예 | RAG 컬렉션 ID. |
| item | query | string (uuid) | 아니오 | RAG 아이템 ID. |
| message | query | string (uuid) | 아니오 | 메시지 ID. |
| asc | query | boolean | 아니오 | 오름차순 정렬. |
| ps | query | integer (int32) | 아니오 | 페이지 크기. |
| p | query | integer (int32) | 아니오 | 1부터 시작하는 페이지 번호. |

**응답 (200):**
```json
{
  "paging": {
    "pageNumber": 1,
    "pageSize": 10,
    "total": 5,
    "totalPages": 1
  },
  "items": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "replyTo": null,
      "questionnaire": null,
      "section": null,
      "question": null,
      "ragCollection": "00000000-0000-0000-0000-000000000000",
      "ragItem": "00000000-0000-0000-0000-000000000000",
      "targetId": "00000000-0000-0000-0000-000000000000",
      "targetType": "Question",
      "targetNum": 1,
      "author": {
        "id": "user123",
        "name": "John Doe",
        "email": "john.doe@example.com",
        "login": "johndoe",
        "ra": true
      },
      "text": "Message content",
      "created": "2025-01-15T10:30:00Z",
      "updated": "2025-01-15T10:30:00Z",
      "replies": 0
    }
  ]
}
```

---

#### POST /questionnaire/rag/messages/add

**요약:** 새 메시지 추가

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | query | string (uuid) | 예 | RAG 컬렉션 ID. |
| item | query | string (uuid) | 아니오 | RAG 아이템 ID. |
| message | query | string (uuid) | 아니오 | 답변할 메시지 ID. |

**요청 본문:**
```json
{
  "text": "New message content"
}
```

**응답 (200):**
```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "replyTo": null,
  "questionnaire": null,
  "section": null,
  "question": null,
  "ragCollection": "00000000-0000-0000-0000-000000000000",
  "ragItem": "00000000-0000-0000-0000-000000000000",
  "targetId": "00000000-0000-0000-0000-000000000000",
  "targetType": "Question",
  "targetNum": 1,
  "author": {
    "id": "user123",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "login": "johndoe",
    "ra": true
  },
  "text": "New message content",
  "created": "2025-01-15T10:30:00Z",
  "updated": "2025-01-15T10:30:00Z",
  "replies": 0
}
```

---

#### POST /questionnaire/rag/message

**요약:** 기존 메시지 업데이트

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| c | query | string (uuid) | 예 | RAG 컬렉션 ID. |
| id | query | string (uuid) | 예 | 메시지 ID. |

**요청 본문:**
```json
{
  "text": "Updated message content"
}
```

**응답 (200):**
```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "replyTo": null,
  "questionnaire": null,
  "section": null,
  "question": null,
  "ragCollection": "00000000-0000-0000-0000-000000000000",
  "ragItem": "00000000-0000-0000-0000-000000000000",
  "targetId": "00000000-0000-0000-0000-000000000000",
  "targetType": "Question",
  "targetNum": 1,
  "author": {
    "id": "user123",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "login": "johndoe",
    "ra": true
  },
  "text": "Updated message content",
  "created": "2025-01-15T10:30:00Z",
  "updated": "2025-01-15T10:45:00Z",
  "replies": 0
}
```

#### DELETE /questionnaire/rag/message

**요약:** 기존 메시지 삭제

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| id | query | string (uuid) | 예 | 메시지 ID. |

**응답 (200):**
```json
{}
```

---

### RagFaq

#### GET /questionnaire/rag/faq-collections/summary

**요약:** 홈 페이지 요약

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| proj | query | string (uuid) | 아니오 | 프로젝트 ID. |

**응답 (200):**
```json
{
  "active": 3
}
```

---

#### GET /questionnaire/rag/faq-collections/total

**요약:** FAQ 컬렉션 수

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| q | query | string | 아니오 | 컬렉션 이름 또는 코드 필터. |
| state | query | array | 아니오 | 상태 필터. |
| project | query | array | 아니오 | 프로젝트 필터. |

**응답 (200):**
```json
3
```

---

#### GET /questionnaire/rag/faq-collections/list

**요약:** FAQ 컬렉션 목록 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| q | query | string | 아니오 | 컬렉션 이름 또는 코드 필터. |
| state | query | array | 아니오 | 상태 필터. |
| project | query | array | 아니오 | 프로젝트 필터. |
| s | query | string | 아니오 | 정렬 필드. |
| asc | query | boolean | 아니오 | 오름차순 정렬. |
| ps | query | integer (int32) | 아니오 | 페이지 크기. |
| p | query | integer (int32) | 아니오 | 1부터 시작하는 페이지 번호. |

**응답 (200):**
```json
{
  "paging": {
    "pageNumber": 1,
    "pageSize": 10,
    "total": 3,
    "totalPages": 1
  },
  "items": [
    {
      "code": "FAQ-001",
      "org": "00000000-0000-0000-0000-000000000000",
      "id": "00000000-0000-0000-0000-000000000000",
      "name": "FAQ Collection",
      "description": "FAQ collection description",
      "documentTypes": null,
      "size": 5,
      "revision": null,
      "type": "Faq",
      "state": "Active",
      "projects": null,
      "items": null,
      "isShared": false
    }
  ]
}
```

---

#### GET /questionnaire/rag/faq-collections/find-items

**요약:** FAQ 항목 검색

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| q | query | string | 예 | 질문 내용 필터. |
| project | query | string (uuid) | 아니오 | 프로젝트 필터. |
| ps | query | integer (int32) | 아니오 | 페이지 크기. |
| p | query | integer (int32) | 아니오 | 1부터 시작하는 페이지 번호. |

**응답 (200):**
```json
{
  "paging": {
    "pageNumber": 1,
    "pageSize": 10,
    "total": 5,
    "totalPages": 1
  },
  "items": [
    {
      "index": 0,
      "question": "What is this product?",
      "answer": "This is a great product.",
      "comment": "Product FAQ",
      "state": "Active"
    }
  ]
}
```

---

#### POST /questionnaire/rag/faq-collection/create

**요약:** 새 FAQ 컬렉션 생성

**요청 본문 (multipart/form-data):**
```json
{
  "code": "FAQ-001",
  "name": "FAQ Collection",
  "description": "FAQ collection description",
  "content": "Content here",
  "file": "binary"
}
```

**응답 (200):**
```json
{
  "code": "FAQ-001",
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "FAQ Collection",
  "description": "FAQ collection description",
  "documentTypes": null,
  "size": 5,
  "revision": null,
  "type": "Faq",
  "state": "Active",
  "projects": null,
  "items": null,
  "isShared": false
}
```

---

#### POST /questionnaire/rag/faq-collection

**요약:** FAQ 컬렉션 메타데이터 업데이트

**요청 본문:**
```json
{
  "code": "FAQ-001",
  "name": "Updated FAQ Collection",
  "description": "Updated description",
  "projects": null,
  "documentTypes": null,
  "isShared": false,
  "state": "Active"
}
```

#### DELETE /questionnaire/rag/faq-collection

**요약:** FAQ 컬렉션 삭제

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |

#### GET /questionnaire/rag/faq-collection

**요약:** FAQ 컬렉션 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |

**응답 (200):**
```json
{
  "code": "FAQ-001",
  "org": "00000000-0000-0000-0000-000000000000",
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "FAQ Collection",
  "description": "FAQ collection description",
  "documentTypes": null,
  "size": 5,
  "revision": null,
  "type": "Faq",
  "state": "Active",
  "projects": null,
  "items": null,
  "isShared": false
}
```

---

#### GET /questionnaire/rag/faq-collection/check

**요약:** FAQ 컬렉션 존재 여부 확인

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |

**응답 (200):**
```json
true
```

---

#### GET /questionnaire/rag/faq-collection/items-total

**요약:** FAQ 항목 수

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |
| q | query | string | 아니오 | FAQ 항목 내용 필터. |

**요청 본문:**
```json
["Active", "Default"]
```

**응답 (200):**
```json
5
```

---

#### GET /questionnaire/rag/faq-collection/items

**요약:** FAQ 항목 목록 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |
| q | query | string | 아니오 | FAQ 항목 내용 필터. |
| state | query | array | 아니오 | 상태 필터. |
| s | query | string | 아니오 | 정렬 필드. |
| asc | query | boolean | 아니오 | 오름차순 정렬. |
| ps | query | integer (int32) | 아니오 | 페이지 크기. |
| p | query | integer (int32) | 아니오 | 1부터 시작하는 페이지 번호. |

**응답 (200):**
```json
{
  "paging": {
    "pageNumber": 1,
    "pageSize": 10,
    "total": 5,
    "totalPages": 1
  },
  "items": [
    {
      "index": 0,
      "question": "What is this product?",
      "answer": "This is a great product.",
      "comment": "Product FAQ",
      "state": "Active"
    }
  ]
}
```

---

#### POST /questionnaire/rag/faq-collection/item/create

**요약:** 새 FAQ 항목 생성

**요청 본문:**
```json
{
  "code": "FAQ-001",
  "index": 0,
  "question": "What is this product?",
  "answer": "This is a great product.",
  "comment": "Product FAQ",
  "state": "Active"
}
```

**응답 (200):**
```json
{
  "index": 0,
  "question": "What is this product?",
  "answer": "This is a great product.",
  "comment": "Product FAQ",
  "state": "Active"
}
```

---

#### GET /questionnaire/rag/faq-collection/item

**요약:** FAQ 항목 조회

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |
| index | query | integer (int32) | 예 | 컬렉션 내 0부터 시작하는 항목 인덱스. |

**응답 (200):**
```json
{
  "index": 0,
  "question": "What is this product?",
  "answer": "This is a great product.",
  "comment": "Product FAQ",
  "state": "Active"
}
```

#### POST /questionnaire/rag/faq-collection/item

**요약:** FAQ 항목 업데이트

**요청 본문:**
```json
{
  "code": "FAQ-001",
  "index": 0,
  "newIndex": 1,
  "question": "Updated question?",
  "answer": "Updated answer.",
  "comment": "Updated comment",
  "state": "Active"
}
```

#### DELETE /questionnaire/rag/faq-collection/item

**요약:** FAQ 항목 삭제

**매개변수:**
| 이름 | 위치 | 유형 | 필수 | 설명 |
|------|------|------|------|------|
| code | query | string | 예 | 컬렉션 코드. |
| index | query | integer (int32) | 예 | 컬렉션 내 0부터 시작하는 항목 인덱스. |

---

### RagQuery

#### POST /questionnaire/rag/query

**요약:** RAG 지식 베이스에 질의 수행

**요청 본문:**
```json
{
  "project": "00000000-0000-0000-0000-000000000000",
  "excludeCollections": [
    "00000000-0000-0000-0000-000000000000"
  ],
  "question": "What is this product?",
  "yourCompanyName": "Acme Corp",
  "yourCompanyAlias": "Acme",
  "customerName": "John Doe",
  "options": [
    "option1",
    "option2"
  ],
  "multiselect": false,
  "nArticles": 5,
  "nFaqs": 3,
  "threshold": 0.5,
  "debug": false,
  "withJustification": true,
  "withConfidenceLevel": true,
  "withFragments": true,
  "nAttempts": 3
}
```

**응답 (200):**
```json
{
  "attempt": 1,
  "preparedQuery": {
    "original": "What is this product?",
    "enhanced": "What is this product and its features?"
  },
  "ragItems": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "distance": 0.25
    }
  ],
  "question": "What is this product?",
  "generalInstructions": "Based on the knowledge base, here is the answer:",
  "text": "This product is a great solution for your needs.",
  "explanation": "The answer was found in multiple sources with high confidence."
}
```

---

#### POST /questionnaire/rag/query-stream

**요약:** RAG 지식 베이스에 스트리밍 질의 수행

**요청 본문:**
```json
{
  "project": "00000000-0000-0000-0000-000000000000",
  "excludeCollections": [
    "00000000-0000-0000-0000-000000000000"
  ],
  "question": "What is this product?",
  "yourCompanyName": "Acme Corp",
  "yourCompanyAlias": "Acme",
  "customerName": "John Doe",
  "options": [
    "option1",
    "option2"
  ],
  "multiselect": false,
  "nArticles": 5,
  "nFaqs": 3,
  "threshold": 0.5,
  "debug": false,
  "withJustification": true,
  "withConfidenceLevel": true,
  "withFragments": true,
  "nAttempts": 3
}
```

**응답 (200):**
```json
[
  {
    "text": "This product is a great solution",
    "fragments": [
      {
        "id": "00000000-0000-0000-0000-000000000000",
        "part": 1,
        "distance": 0.25,
        "type": "Article",
        "code": "ART-001",
        "title": "Product Title",
        "fragment": "Product content fragment"
      }
    ]
  },
  {
    "text": " for your needs.",
    "fragments": []
  }
]
```

---

#### POST /questionnaire/rag/query-fragments

**요약:** RAG 지식 베이스에 조각 단위 질의 수행

**요청 본문:**
```json
{
  "project": "00000000-0000-0000-0000-000000000000",
  "exclude_documents": [
    "00000000-0000-0000-0000-000000000000"
  ],
  "query": "What is this product?",
  "top_k": 5,
  "similarity_threshold": 0.5,
  "prepare_query": true
}
```

**응답 (200):**
```json
{
  "results": [
    {
      "document_id": "00000000-0000-0000-0000-000000000000",
      "document_code": "ART-001",
      "document_title": "Product Title",
      "revision": 3,
      "chunk_index": 0,
      "content": "Product content fragment",
      "metadata": {
        "author": "John Doe",
        "created_at": "2025-01-15T10:30:00Z",
        "last_updated_at": "2025-01-15T10:35:00Z",
        "doc_categories": [
          "Product",
          "Information"
        ]
      },
      "similarity_score": 0.85
    }
  ]
}
```

## 관련 문서

- [API 토큰 – 생성 및 관리](/api-tokens/) – 토큰 생성 및 관리 방법
- [지식 베이스로 AI에게 질문하기](/ask-ai-with-your-knowledge-base/) – RAG 질의 사용법