BaşlayınÜcretsiz Başlayın

Creating a RAG chain

Now to bring all the components together in your RAG workflow! You've prepared the documents and ingested them into a Chroma database for retrieval. You created a prompt template to include the retrieved chunks from the academic paper and answer questions.

The prompt template you created in the previous exercise is available as prompt_template, an OpenAI model has been initialized as llm, and the code to recreate your retriever has be included in the script.

Bu egzersiz

Developing LLM Applications with LangChain

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create an LCEL chain using the pipe operator (|) to connect retriever, prompt_template, and llm in sequence.
  • The chain should map the retriever to "context" and user input to "question".
  • Invoke the chain using the .invoke() method on the question provided.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

vectorstore = Chroma.from_documents(
    docs,
    embedding=OpenAIEmbeddings(api_key='', model='text-embedding-3-small'),
    persist_directory=os.getcwd()
)

retriever = vectorstore.as_retriever(
    search_type="similarity",
    search_kwargs={"k": 3}
)

# Create a chain to link retriever, prompt_template, and llm
rag_chain = ({"context": ____, "question": ____}
            | prompt_template
            | llm)

# Invoke the chain
response = rag_chain.____("Which popular LLMs were considered in the paper?")
print(response.content)
Kodu Düzenle ve Çalıştır