Lamini Memory RAG — 문서 인덱스와 질의

Lamini Memory RAG

Memory RAG는 GPT-4와 비교했을 때 LLM 정확도를 약 **50% → 90~95%**로 끌어올리는 간단한 접근 방식이에요. 의미와 관계를 담는 컨텍스트 임베딩을 만들어서, 복잡한 RAG 설정이나 파인튜닝 오버헤드 없이도 작은 모델이 높은 정확도를 내는 게 핵심이에요.

빠른 시작

API 키를 설정한 뒤, 문서를 업로드하고 베이스 오픈소스 LLM을 선택해 인덱스를 만들어요.

from lamini import MemoryRAG

client = MemoryRAG("meta-llama/Llama-3.1-8B-Instruct")

PDF 파일을 받아서 임베딩하고 인덱스를 만들어요.

lamini_wikipedia_page_pdf = ("https://huggingface.co/datasets/lamini/"
                            "lamini-wikipedia-page/blob/main/"
                            "Lamini-wikipedia-page.pdf")
import requests, os
response = requests.get(lamini_wikipedia_page_pdf)
pdf_path = "lamini_wikipedia.pdf"
with open(pdf_path, "wb") as f:
    f.write(response.content)

response = client.memory_index(documents=[pdf_path])
# {'job_id': 1, 'status': 'CREATED'}

client.status(job_id)로 상태를 폴링한 뒤, 프롬프트를 만들어 질의해요.

user_prompt = "How is lamini related to llamas?"
prompt_template = "<|begin_of_text|><|start_header_id|>user<|end_header_id|>

 {prompt} <|eot_id|><|start_header_id|>assistant<|end_header_id|>

"
prompt = prompt_template.format(prompt=user_prompt)
response = client.query(prompt)

반복하기

질문/답변 쌍으로 평가셋을 만들어 모델 성능을 측정해요. 성능이 낮으면 추가 데이터로 Memory RAG 잡을 다시 돌리고, 충분히 좋아지면 프로덕션에 올릴 준비가 됐다고 보면 돼요.

더 알아보기