Bir LCEL alma zinciri oluşturma

LangChain ile Retrieval Augmented Generation (RAG)

Meri Nova

Machine Learning Engineer

Alma için verileri hazırlama

Belge parçaları depolanır.

LangChain ile Retrieval Augmented Generation (RAG)

RAG için LCEL’e giriş

Bir kullanıcı girdisi.

LangChain ile Retrieval Augmented Generation (RAG)

RAG için LCEL’e giriş

Bir kullanıcı girdisi RunnablePassthrough ile zincire girer ve "question" olarak atanır.

LangChain ile Retrieval Augmented Generation (RAG)

RAG için LCEL’e giriş

Girdi, alma modülünü sorgulamak için kullanılır ve "context" olarak atanır.

LangChain ile Retrieval Augmented Generation (RAG)

RAG için LCEL’e giriş

"context" ve "question" istem şablonuna entegre edilir.

LangChain ile Retrieval Augmented Generation (RAG)

RAG için LCEL’e giriş

Bir çıktıyı üretmek için istemin LLM'e, yani modele, entegre edilmesi.

LangChain ile Retrieval Augmented Generation (RAG)

RAG için LCEL’e giriş

Model çıktısının bir ayrıştırıcıya iletilmesi.

LangChain ile Retrieval Augmented Generation (RAG)

Bir alma modülü başlatma

vector_store = Chroma.from_documents(
    documents=chunks, 
    embedding=embedding_model
)


retriever = vector_store.as_retriever( search_type="similarity", search_kwargs={"k": 2} )
LangChain ile Retrieval Augmented Generation (RAG)

Bir istem şablonu oluşturma

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_template(""" Use the following pieces of context to answer the question at the end. If you don't know the answer, say that you don't know. Context: {context} Question: {question} """)
llm = ChatOpenAI(model="gpt-4o-mini", api_key="...", temperature=0)
LangChain ile Retrieval Augmented Generation (RAG)

Bir LCEL alma zinciri kurma

from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser

chain = (
{"context": retriever, "question": RunnablePassthrough()}
| prompt
| llm
| StrOutputParser()
)
LangChain ile Retrieval Augmented Generation (RAG)

Alma zincirini çağırma

result = chain.invoke({"question": "What are the key findings or results presented in the paper?"})
print(result)
- Top Performance: RAG models set new records on open-domain question answering tasks...
- Better Generation: RAG models produce more specific, diverse, and factual language...
- Dynamic Knowledge Use: The non-parametric memory allows RAG models to access and ...
LangChain ile Retrieval Augmented Generation (RAG)

Hadi pratik yapalım!

LangChain ile Retrieval Augmented Generation (RAG)

Preparing Video For Download...