질문 「How many people still live in extreme poverty?」로 176개 청크와 거리를 재어 가까운 순으로 뽑은 결과다. 각 결과에 어느 Goal, 몇 쪽인지가 함께 붙어 나온다 — STEP 4에서 심어 둔 메타데이터다.We measured the query “How many people still live in extreme poverty?” against all 176 chunks and took the closest ones. Each result arrives with its Goal and page range attached — the metadata we planted back in STEP 4.
흔히 “검색해서 LLM이 답한다”고 말하지만, 그 사이에 조립이 있다. 찾아낸 청크 세 개는 그대로 모델에게 갈 수 없다 — 하나의 긴 텍스트로 합쳐지고, 앞뒤에 지시문과 질문이 붙는다.People say “it retrieves and the LLM answers,” but between the two sits assembly. The three chunks cannot go to the model as they are — they are joined into one long text, wrapped in an instruction and a question.
아래가 모델이 받는 텍스트 전부다. 가공하지 않았다. 「조립하기」를 누르면 어떤 순서로 쌓이는지 보인다.Below is everything the model receives, unedited. Press “Assemble” to watch the order in which it stacks up.
k)를 바꾸면 프롬프트가 얼마나 길어지는지 보인다Change k — the number of chunks retrieved — to see how the prompt grows모델의 기억이 아니라 준 자료 안에서만 답하도록 못 박는다. 찾을 수 없으면 없다고 말하라는 지시도 함께 넣는다.It pins the model to the supplied material rather than its own memory, and tells it to say so when the answer is not there.
모델이 볼 수 있는 것은 이것뿐이다. 여기 없는 내용이 답변에 나오면 그건 모델이 지어낸 것이다.This is all the model can see. If something appears in the answer that is not here, the model invented it.
조립된 프롬프트가 LLM으로 들어가고, 모델은 그 텍스트를 읽어 이어질 말을 생성한다. 지시문 때문에 그 재료 안에서 답하게 된다.The assembled prompt goes in, and the model generates what should come next. The instruction is what keeps it inside the supplied material.
모델의 출력은 실습에서 각자 직접 확인한다. 지어낸 답변을 실을 수는 없고, 같은 프롬프트라도 환경에 따라 결과가 달라질 수 있기 때문이다. STEP 10을 실행하면 바로 이 프롬프트가 들어가고, 그 답이 화면에 찍힌다.You will see the output in the notebook, on your own machine. We will not print an invented answer, and the same prompt can yield different text in different setups. Run STEP 10 and this exact prompt goes in — the reply appears on your screen.
results = store.similarity_search_with_score(q, k=3) context = "\n\n".join(doc.page_content for doc, _ in results) prompt = ("Use only the following sources…" f"{context}\n\nQuestion: {q}") answer = llm.invoke(prompt) # ← 여기서 생성된다generated here
답변만 내놓으면 확인할 방법이 없다. 그래서 답을 만드는 데 쓴 청크의 출처를 함께 출력한다. 이 세 줄은 새로 만든 것이 아니라, 검색 결과에 이미 붙어 있던 metadata를 그대로 옮긴 것이다.An answer alone cannot be checked. So we print the source of every chunk used alongside it. These lines are not newly composed — they are the metadata that already rode along with each search result.
print("\nSources") for doc, _ in results: m = doc.metadata print(f" [{m['id']}] Goal {m['goal']} {m['goal_name']} · pp. {m['pages']}")
모델은 자기가 어느 문서를 읽었는지 말해 주지 않는다. 말해 줄 수 있는 것은 우리가 어느 청크를 골라 넣었는지 알고 있기 때문이다. STEP 3에서 구조를 세우고, STEP 4에서 메타데이터를 심고, STEP 6에서 원문과 함께 저장해 둔 그 모든 준비가 이 세 줄을 위한 것이었다.The model cannot tell you which documents it read. We can — because we chose which chunks to put in. Building the structure in STEP 3, planting the metadata in STEP 4, storing text beside vectors in STEP 6: all of it was for these three lines.
여기까지가 열 단계다. PDF 한 편에서 시작해, 구조를 세우고, 조각으로 나누고, 좌표로 옮기고, 색인에 담고, 거리를 재어 찾고, 프롬프트로 조립해, 답변과 출처를 얻었다.That is all ten steps. From one PDF: build the structure, cut it into chunks, move them into coordinates, file them in an index, measure distance to find them, assemble a prompt, and get back an answer with its sources.
Source/sdg_embeddings.jsonl과 workshop_code.md의 실제 템플릿으로 조립한 것입니다 · 모델이 생성한 답변은 싣지 않았습니다Results and prompt were assembled from the real Source/sdg_embeddings.jsonl and the actual template in workshop_code.md · No model-generated answer is reproduced