PDF를 올려놓고 물어보면 답해주는 챗봇. Dify로 만들 수 있다.

그런데 올리기 전에 정해야 하는 설정이 하나 있다. 나중에 바꿀 수 없는 거다.

PDF를 올리면 안에서 벌어지는 일

Dify는 올린 문서를 '지식베이스'에 넣는다. 그리고 질문이 들어오면 이렇게 움직인다.

  • 검색 — 질문과 가장 관련 있는 부분을 지식베이스에서 찾는다
  • 결합 — 찾은 내용을 원래 질문에 붙여 모델에게 넘긴다
  • 생성 — 모델이 그 내용을 근거로 답을 만든다

이 방식을 RAG라고 부른다. 모델이 학습해 둔 지식만 쓰는 게 아니라, 내가 올린 문서를 추가 근거로 삼는 것이다.

여기서 중요한 게 하나 있다. 문서 전체를 통째로 모델에게 주는 게 아니다.

Dify는 문서를 '청크'라는 작은 조각으로 쪼갠다. 공식 문서는 이걸 긴 책을 장과 문단으로 정리하는 일에 비유한다. 질문이 오면 그 조각들 중에서 관련 있는 것만 찾아 쓴다.

매번 문서 전체를 처리하면 느리고 비싸기 때문이다.

만들고 나면 못 바꾸는 설정

청크 모드는 지식베이스를 만든 뒤에는 바꿀 수 없다. 구분자나 최대 길이 같은 세부 설정은 언제든 조정되지만, 모드 자체는 처음에 정하면 끝이다.

모드는 둘이다.

일반(General) 모드는 모든 청크가 같은 설정을 쓰고, 질문에 걸린 청크를 그대로 답의 근거로 돌려준다. 청크가 서로 겹치는 정도(오버랩)를 조절할 수 있다.

부모-자식(Parent-child) 모드는 두 층으로 쪼갠다. 작은 자식 청크와 큰 부모 청크를 만들어 두고, 질문이 자식에 걸리면 그 자식이 속한 부모 전체를 돌려준다.

찾기는 좁게 하고 답할 때는 넓은 맥락을 주는 방식이다. 여러 쪽에 걸쳐 설명이 이어지는 PDF라면 이쪽이 맞을 가능성이 크다.

구분자에도 함정이 있다.

구분자는 쪼개는 기준이면서 동시에 본문에서 지워진다. 공식 문서의 예시가 명확하다 — A를 구분자로 쓰면 CBACD가 CB와 CD로 갈리고 A는 사라진다. 그래서 문서에 실제로 등장하는 문자를 구분자로 쓰면 내용이 조용히 없어진다.

문단 단위로 자르려면 빈 줄, 줄 단위로 자르려면 줄바꿈을 쓴다. 최대 길이를 넘는 부분은 구분자와 상관없이 강제로 잘린다.

잘 되는지 확인하는 법

챗봇에 붙이기 전에 검색이 제대로 되는지 먼저 볼 수 있다. 지식베이스 왼쪽 사이드바의 '검색 테스트'로 들어가 질문을 넣어보면, 어떤 조각이 걸리는지 그대로 보인다.

여기서 바꾼 검색 설정은 그 테스트 세션에만 적용된다. 마음에 든다고 저장된 게 아니라는 뜻이다.

기록(Records) 항목에는 이 지식베이스에 들어온 검색이 전부 남는다. 테스트에서 넣은 질문뿐 아니라 연결된 앱이 실제로 보낸 요청까지 함께다. 테스트 검색과 실제 검색은 같은 API를 쓴다.

무료 플랜으로 어디까지 되는지도 미리 알아두는 게 좋다. Dify 샌드박스는 지식 문서 50개, 저장공간 50MB까지다. PDF 몇 개 올려보는 정도는 되지만 자료가 쌓이면 곧 닿는다.

정리하면, 순서가 중요하다. 청크 모드를 먼저 정하고, 문서에 없는 문자를 구분자로 고르고, 검색 테스트로 확인한 다음 챗봇에 붙인다.

거꾸로 하면 지식베이스를 다시 만드는 수밖에 없다..

Upload a PDF, ask questions about it, get answers. You can build that with Dify.

But one setting has to be decided before you upload anything, because you cannot change it afterwards.

What happens when you upload a PDF

Dify puts the document into a knowledge base. When a question arrives, it works in three steps.

  • Retrieval — it finds the parts of the knowledge base most relevant to the question
  • Augmented — that retrieved text is combined with the original query and passed to the model
  • Generation — the model uses that context to produce a more precise answer

This is called RAG. Instead of relying only on what the model learned during training, it treats your document as an additional source of truth.

One thing matters here: the whole document is not handed to the model.

Dify splits documents into small pieces called chunks. The official docs compare it to organizing a long book into chapters and paragraphs — when a question comes in, only the relevant pieces get used.

Processing an entire document for every query would be slow and expensive.

The setting you cannot change later

The chunk mode cannot be changed once the knowledge base is created. Details like the delimiter and maximum chunk length can be adjusted at any time, but the mode itself is fixed at creation.

There are two modes.

In General mode every chunk shares the same settings, and a matched chunk is returned directly as the retrieval result. You can also set how much neighbouring chunks overlap.

In Parent-child mode the text is split into two tiers: smaller child chunks and larger parent chunks. When a query matches a child, the entire parent chunk is returned instead.

Search narrowly, answer with wider context. For a PDF where an explanation runs across several pages, this is likely the better fit.

Delimiters have a trap of their own.

A delimiter marks where text splits, and it is also removed from the text. The docs give a clear example: using A as the delimiter turns CBACD into CB and CD, and the A is gone. So choosing a character that actually appears in your document silently deletes content.

Use a blank line to split on paragraphs, or a line break to split on lines. Anything past the maximum chunk length is force-split regardless of the delimiter.

Checking whether it actually works

You can test retrieval before wiring it into a chatbot. Click Retrieval Testing in the knowledge base sidebar, enter a query, and you see exactly which chunks come back.

Retrieval settings you adjust there are temporary and apply only to that test session — liking a result does not save it.

The Records section logs every retrieval against that knowledge base: queries you typed on the testing page and requests from any linked app. Test retrievals and regular retrievals share the same API endpoint.

It also helps to know where the free tier stops. Dify's Sandbox plan allows 50 knowledge documents and 50MB of storage. Enough to try a few PDFs, not enough once material accumulates.

So the order matters: pick the chunk mode, choose a delimiter that does not appear in your document, verify with retrieval testing, then connect the chatbot.

Do it backwards and your only option is to build the knowledge base again..

Sources · Dify · Dify · Dify · Dify