A large language model (LLM) is a generative AI model trained on a large collection of text, or text corpus, to produce natural-language responses. It can explain, summarize, and translate recipes, but a family recipe absent from its training data presents a practical question: how should the application give the model access to it? section 14.1 section 14.2
Two ways to incorporate a recipe are:
- Fine-tune an existing model with an additional training cycle. This can incorporate the recipe while retaining the model’s other capabilities, but new batches require retraining. Computing, hosting, and distinguishing original knowledge from added recipes are further challenges. section 14.2
- Use retrieval-augmented generation (RAG). Store recipes in a vector database, retrieve relevant documents for a question, and give them to the language model through a prompt so it can generate an answer. section 14.0 section 14.10.3
Answering a recipe question
A recipe chat asks, “What’s the recipe for chocolate cookies?” Its Python workflow connects a vector store and an AzureChatOpenAI model to a retrieval chain. When a requested recipe is stored, the assistant can return ingredients and steps; when it is not, the assistant says it does not know that recipe. Stored recipes can also support translation and suggestions based on available ingredients. section 14.10.3
Listing 14.16 Interacting with the vector database via Python
# IMPORTANT!! To run this implementation, Don't forget to make sure
# the environment variables we declared in the .env files
# are accessible in the Python environment.
from langchain_openai.chat_models import AzureChatOpenAI
from langchain_openai import AzureOpenAIEmbeddings
from langchain_weaviate.vectorstores import WeaviateVectorStore
from langchain.chains import create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain
from vectorvault.chat.pages.utils import PROMPT
import weaviate
import os
import json
question = "Whats the recipe for chocolate cookies?"
openai_client = AzureChatOpenAI( #1
model_name="gpt-4",
deployment_name = "gpt-4",
api_version="2024-02-01",
)
with weaviate.connect_to_local(
port=8083,
grpc_port=50051,
headers = {"X-Azure-Api-Key": os.getenv('OPENAI_API_KEY')},
) as weaviate_client: #2
weaviate_db = WeaviateVectorStore( #3
client=weaviate_client,
index_name="recipes",
text_key="chunk",
embedding=AzureOpenAIEmbeddings(model="text-embedding-3-large")
)
rag_chain = create_retrieval_chain(
weaviate_db.as_retriever(), #4
create_stuff_documents_chain(openai_client, PROMPT), #5
)
output = rag_chain.invoke({#6
"input": question,
"chat_history": None #7
}
)
print(json.loads(output["answer"])) #8
{
'answer': 'Here is the recipe for the Best Chocolate Chip Cookies:\n\n
Ingredients:\n- 1 cup butter, softened\n- 1 cup white sugar\n
- 1 cup packed brown sugar\n- 2 large eggs\n- 2 teaspoo...',
'provided_recipe': True
}
The Python listing shows the named model client, vector store, retrieval-chain imports, and sample question used in the recipe workflow. section 14.10.3


































































