# CH14 chain (Chains)

The chain creation phase is a step that binds all of the previous seven-step processes together and assembles them into one RAG pipeline to complete.

The structure below represents the structure of the document-based RAG.

* [LCEL grammar](https://wikidocs.net/233344)
* [LangChain Chains](https://python.langchain.com/v0.1/docs/modules/chains/)

### Reference <a href="#id-2" id="id-2"></a>

```python
# Run Chain
# Enter a query for the document and print out the answer.
question = "The name of the AI ​​developed by Samsung Electronics is?"
response = chain.invoke(question)
```

Below is the quintet code for the finished chain.

```python
# Create a Chain
chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)
```

LCEL (LangChain Expression Language) grammar is used to tie the entire process of the previous 7 steps into one chain.

### Reference <a href="#id-2" id="id-2"></a>

* [LCEL grammar](https://wikidocs.net/233344)
* [LangChain Chains](https://python.langchain.com/v0.1/docs/modules/chains/)

<br>
