Chapter 112
"Agentic" RAG
Follow along this tutorial: https://github.com/alexeygrigorev/rag-agents-workshop
!pip install minsearchimport requests
docs_url = 'https://github.com/alexeygrigorev/llm-rag-workshop/raw/main/notebooks/documents.json'
docs_response = requests.get(docs_url)
documents_raw = docs_response.json()
documents = []
for course in documents_raw:
course_name = course['course']
for doc in course['documents']:
doc['course'] = course_name
documents.append(doc)from minsearch import AppendableIndex
index = AppendableIndex(
text_fields=["question", "text", "section"],
keyword_fields=["course"]
)
index.fit(documents)Output
C:\Users\alexe\miniconda3\Lib\site-packages\sklearn\utils\_param_validation.py:11: UserWarning: A NumPy version >=1.23.5 and <2.3.0 is required for this version of SciPy (detected version 2.3.0) from scipy.sparse import csr_matrix, issparse
<minsearch.append.AppendableIndex at 0x233d5173b90>
def search(query):
boost = {'question': 3.0, 'section': 0.5}
results = index.search(
query=query,
filter_dict={'course': 'data-engineering-zoomcamp'},
boost_dict=boost,
num_results=5,
output_ids=True
)
return resultsquestion = 'Can I still join the course?'prompt_template = """
You're a course teaching assistant. Answer the QUESTION based on the CONTEXT from the FAQ database.
Use only the facts from the CONTEXT when answering the QUESTION.
<QUESTION>
{question}
</QUESTION>
<CONTEXT>
{context}
</CONTEXT>
""".strip()
def build_prompt(query, search_results):
context = ""
for doc in search_results:
context = context + f"section: {doc['section']}\nquestion: {doc['question']}\nanswer: {doc['text']}\n\n"
prompt = prompt_template.format(question=query, context=context).strip()
return promptsearch_results = search(question)prompt = build_prompt(question, search_results)from openai import OpenAI
client = OpenAI()
def llm(prompt):
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
answer = llm(prompt)print(answer)Output
Yes, you can still join the course after the start date. Even if you don't register, you're eligible to submit the homeworks. However, be aware that there will be deadlines for turning in the final projects, so it's best not to leave everything for the last minute.
def rag(query):
search_results = search(query)
prompt = build_prompt(query, search_results)
answer = llm(prompt)
return answerrag("How do I patch KDE under FreeBSD?")Output
'I’m sorry, but there is no information available in the context regarding how to patch KDE under FreeBSD.'
"Agentic" RAG
prompt_template = """
You're a course teaching assistant.
You're given a QUESTION from a course student and that you need to answer with your own knowledge and provided CONTEXT.
At the beginning the context is EMPTY.
<QUESTION>
{question}
</QUESTION>
<CONTEXT>
{context}
</CONTEXT>
If CONTEXT is EMPTY, you can use our FAQ database.
In this case, use the following output template:
{{
"action": "SEARCH",
"reasoning": "<add your reasoning here>"
}}
If you can answer the QUESTION using CONTEXT, use this template:
{{
"action": "ANSWER",
"answer": "<your answer>",
"source": "CONTEXT"
}}
If the context doesn't contain the answer, use your own knowledge to answer the question
{{
"action": "ANSWER",
"answer": "<your answer>",
"source": "OWN_KNOWLEDGE"
}}
""".strip()question = 'Can I still join the course?'
context = 'EMPTY'prompt = prompt_template.format(question=question, context=context)answer_json = llm(prompt)import jsonanswer = json.loads(answer_json)answer['action']Output
'SEARCH'
def build_context(search_results):
context = ""
for doc in search_results:
context = context + f"section: {doc['section']}\nquestion: {doc['question']}\nanswer: {doc['text']}\n\n"
return context.strip()search_results = search(question)
context = build_context(search_results)
prompt = prompt_template.format(question=question, context=context)answer_json = llm(prompt)print(answer_json)Output
{
"action": "ANSWER",
"answer": "Yes, you can still join the course even after the start date. Even if you haven't registered, you're eligible to submit homework. Just keep in mind that there will be deadlines for the final projects, so it's a good idea to stay on top of the deadlines and not leave things until the last minute.",
"source": "CONTEXT"
}
Agentic Search
def dedup(seq):
seen = set()
result = []
for el in seq:
_id = el['_id']
if _id in seen:
continue
seen.add(_id)
result.append(el)
return resultprompt_template = """
You're a course teaching assistant.
You're given a QUESTION from a course student and that you need to answer with your own knowledge and provided CONTEXT.
The CONTEXT is build with the documents from our FAQ database.
SEARCH_QUERIES contains the queries that were used to retrieve the documents
from FAQ to and add them to the context.
PREVIOUS_ACTIONS contains the actions you already performed.
At the beginning the CONTEXT is empty.
You can perform the following actions:
- Search in the FAQ database to get more data for the CONTEXT
- Answer the question using the CONTEXT
- Answer the question using your own knowledge
For the SEARCH action, build search requests based on the CONTEXT and the QUESTION.
Carefully analyze the CONTEXT and generate the requests to deeply explore the topic.
Don't use search queries used at the previous iterations.
Don't repeat previously performed actions.
Don't perform more than {max_iterations} iterations for a given student question.
The current iteration number: {iteration_number}. If we exceed the allowed number
of iterations, give the best possible answer with the provided information.
Output templates:
If you want to perform search, use this template:
{{
"action": "SEARCH",
"reasoning": "<add your reasoning here>",
"keywords": ["search query 1", "search query 2", ...]
}}
If you can answer the QUESTION using CONTEXT, use this template:
{{
"action": "ANSWER_CONTEXT",
"answer": "<your answer>",
"source": "CONTEXT"
}}
If the context doesn't contain the answer, use your own knowledge to answer the question
{{
"action": "ANSWER",
"answer": "<your answer>",
"source": "OWN_KNOWLEDGE"
}}
<QUESTION>
{question}
</QUESTION>
<SEARCH_QUERIES>
{search_queries}
</SEARCH_QUERIES>
<CONTEXT>
{context}
</CONTEXT>
<PREVIOUS_ACTIONS>
{previous_actions}
</PREVIOUS_ACTIONS>
""".strip()question = 'how do I do well on module 1'
max_iterations = 3
iteration_number = 0
search_queries = []
search_results = []
previous_actions = []context = build_context(search_results)
prompt = prompt_template.format(
question=question,
context=context,
search_queries="\n".join(search_queries),
previous_actions='\n'.join([json.dumps(a) for a in previous_actions]),
max_iterations=max_iterations,
iteration_number=iteration_number
)answer_json = llm(prompt)answer = json.loads(answer_json)previous_actions.append(answer)keywords = answer['keywords']for kw in keywords:
search_queries.append(kw)
sr = search(kw)
search_results.extend(sr)search_results = dedup(search_results)iteration_number = 2
context = build_context(search_results)
prompt = prompt_template.format(
question=question,
context=context,
search_queries="\n".join(search_queries),
previous_actions='\n'.join([json.dumps(a) for a in previous_actions]),
max_iterations=max_iterations,
iteration_number=iteration_number
)answer_json = llm(prompt)print(answer['answer'])Output
To do well in Module 1 focused on Docker and Terraform, consider the following strategies: 1. **Understand Core Concepts**: Take time to understand the fundamental concepts of Docker and Terraform. Focus on how containers work in Docker and the infrastructure as code principles in Terraform. 2. **Hands-On Practice**: Engage in hands-on projects. Try to build your own Docker containers and deploy them. Similarly, create Terraform scripts to automate infrastructure deployment. 3. **Utilize Documentation**: Use the official documentation for both Docker and Terraform as a primary resource. They provide excellent examples and use cases that can reinforce your learning. 4. **Engage with the Community**: Participate in forums or community discussions related to Docker and Terraform. You can learn a lot from others' experiences and solutions to common problems. 5. **Study Regularly**: Create a study schedule that allows you to consistently review material and practice coding, rather than cramming before assessments. 6. **Experiment**: Don’t hesitate to experiment with new features in both Docker and Terraform. This will not only enhance your understanding but also prepare you for working in real-world scenarios. In addition, ensure you troubleshoot common errors, like those related to installation or configuration of these tools, as familiarity with resolving issues will enhance your practical skills and confidence.
question = "what do I need to do to be successful at module 1?"
search_queries = []
search_results = []
previous_actions = []
iteration = 0
while True:
print(f'ITERATION #{iteration}...')
context = build_context(search_results)
prompt = prompt_template.format(
question=question,
context=context,
search_queries="\n".join(search_queries),
previous_actions='\n'.join([json.dumps(a) for a in previous_actions]),
max_iterations=3,
iteration_number=iteration
)
print(prompt)
answer_json = llm(prompt)
answer = json.loads(answer_json)
print(json.dumps(answer, indent=2))
previous_actions.append(answer)
action = answer['action']
if action != 'SEARCH':
break
keywords = answer['keywords']
search_queries = list(set(search_queries) | set(keywords))
for k in keywords:
res = search(k)
search_results.extend(res)
search_results = dedup(search_results)
iteration = iteration + 1
if iteration >= 4:
break
print()answerOutput
{'action': 'ANSWER',
'answer': "To be successful in Module 1, which focuses on Docker and Terraform, consider the following strategies: \n\n1. **Hands-on Practice**: Engage in hands-on projects to solidify your understanding of Docker and Terraform. Setting up your own Docker containers and writing Terraform scripts will help reinforce the concepts. \n\n2. **Resources**: Use official documentation for both Docker and Terraform extensively. They're comprehensive and can provide guidance on best practices. \n\n3. **Community Support**: Participate in forums and community groups related to Docker and Terraform. Platforms like Stack Overflow or specific Slack channels can be helpful for problem-solving and learning from others' experiences. \n\n4. **Time Management**: Allocate time regularly each week to study and practice. Break down the module into manageable sections and create a study schedule. \n\n5. **Study Groups**: Collaborate with peers for group study sessions. Explaining concepts to others can enhance your own understanding. \n\n6. **Experiment**: Don't hesitate to experiment with different features of Docker and Terraform. Breaking things and fixing them is a part of learning. \n\n7. **Seek Feedback**: If you’re working on assignments or projects, seek feedback from your instructors or peers to identify areas for improvement. \n\nBy combining these strategies, you’ll be better prepared to tackle the challenges presented in Module 1 effectively.",
'source': 'OWN_KNOWLEDGE'}iterationOutput
3
Function calling ("tool use")
def search(query):
boost = {'question': 3.0, 'section': 0.5}
results = index.search(
query=query,
filter_dict={'course': 'data-engineering-zoomcamp'},
boost_dict=boost,
num_results=5,
output_ids=True
)
return resultssearch_tool = {
"type": "function",
"name": "search",
"description": "Search the FAQ database",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query text to look up in the course FAQ."
}
},
"required": ["query"],
"additionalProperties": False
}
}def do_call(tool_call_response):
function_name = tool_call_response.name
arguments = json.loads(tool_call_response.arguments)
f = globals()[function_name]
result = f(**arguments)
return {
"type": "function_call_output",
"call_id": tool_call_response.call_id,
"output": json.dumps(result, indent=2),
}question = "How do I do well in module 1?"
developer_prompt = """
You're a course teaching assistant.
You're given a question from a course student and your task is to answer it.
If you look up something in FAQ, convert the student question into multiple queries.
""".strip()
tools = [search_tool]
chat_messages = [
{"role": "developer", "content": developer_prompt},
{"role": "user", "content": question}
]
response = client.responses.create(
model='gpt-4o-mini',
input=chat_messages,
tools=tools
)
response.outputOutput
[ResponseFunctionToolCall(arguments='{"query":"module 1 tips for success"}', call_id='call_FcpWXGZqHeLqMecDQwLCMPXq', name='search', type='function_call', id='fc_686401a3efbc8191b3646e3ad1218ac80e0676c3b7e4712d', status='completed'),
ResponseFunctionToolCall(arguments='{"query":"how to excel in module 1"}', call_id='call_PNjiVZq3Fe66ODLrgup0SaRm', name='search', type='function_call', id='fc_686401a4e5448191a158f243fe1518b80e0676c3b7e4712d', status='completed')]calls = response.outputfor call in calls:
result = do_call(call)
chat_messages.append(call)
chat_messages.append(result)response = client.responses.create(
model='gpt-4o-mini',
input=chat_messages,
tools=tools
)
response.outputOutput
[ResponseOutputMessage(id='msg_686401ebe13c81918f6f3c84a1e7cec00e0676c3b7e4712d', content=[ResponseOutputText(annotations=[], text='To do well in Module 1, here are some tips based on common challenges and solutions:\n\n1. **Understand Your Environment**:\n - Ensure that you have set up your development environment correctly. This includes installing Docker and Terraform as indicated in the module resources.\n\n2. **Common Installation Issues**:\n - If you encounter errors such as `ModuleNotFoundError: No module named \'psycopg2\'`, try installing it via:\n ```bash\n pip install psycopg2-binary\n ```\n - If you\'re still encountering issues, consider updating pip or conda:\n ```bash\n pip install --upgrade pip\n ```\n or\n ```bash\n conda update -n base -c defaults conda\n ```\n\n3. **PostgreSQL Connectivity**:\n - When connecting to PostgreSQL using SQLAlchemy, ensure your connection string is formatted correctly, for example:\n ```python\n conn_string = "postgresql+psycopg://username:password@localhost:5432/your_database"\n ```\n - If you face errors related to the connection, make sure PostgreSQL is installed and running.\n\n4. **Hands-on Practice**:\n - Engage in hands-on exercises that utilize Docker and Terraform. The more you practice, the more comfortable you\'ll be with the concepts.\n\n5. **Use Provided Resources**:\n - Refer to any supplementary materials provided in the course for additional guidance on technical setups and exercises.\n\n6. **Seek Help if Needed**:\n - Don’t hesitate to reach out to instructors or peers if you run into any issues. The course community can be a valuable resource.\n\nFollowing these tips should enhance your understanding and performance in Module 1! If you have specific topics you\'d like more detail on, feel free to ask.', type='output_text', logprobs=[])], role='assistant', status='completed', type='message')]
for entry in response.output:
chat_messages.append(entry)
print(entry.type)
if entry.type == 'function_call':
result = do_call(entry)
chat_messages.append(result)
elif entry.type == 'message':
print(entry.text) developer_prompt = """
You're a course teaching assistant.
You're given a question from a course student and your task is to answer it.
Use FAQ if your own knowledge is not sufficient to answer the question.
When using FAQ, perform deep topic exploration: make one request to FAQ,
and then based on the results, make more requests.
At the end of each response, ask the user a follow up question based on your answer.
""".strip()
chat_messages = [
{"role": "developer", "content": developer_prompt},
]while True: # main Q&A loop
question = input() # How do I do my best for module 1?
if question == 'stop':
break
message = {"role": "user", "content": question}
chat_messages.append(message)
while True: # request-response loop - query API till get a message
response = client.responses.create(
model='gpt-4o-mini',
input=chat_messages,
tools=tools
)
has_messages = False
for entry in response.output:
chat_messages.append(entry)
if entry.type == 'function_call':
print('function_call:', entry)
print()
result = do_call(entry)
chat_messages.append(result)
elif entry.type == 'message':
print(entry.content[0].text)
print()
has_messages = True
if has_messages:
breakOutput
How do I do well in module 1?
function_call: ResponseFunctionToolCall(arguments='{"query":"module 1 tips"}', call_id='call_IED9lyUZOsS6ToxvZHLNQoN6', name='search', type='function_call', id='fc_686403087180819ebf792db8930e3f830594799b59703b57', status='completed')
function_call: ResponseFunctionToolCall(arguments='{"query":"module 1 successful strategies"}', call_id='call_WAvKTixmfYyoBrF89lS6N46R', name='search', type='function_call', id='fc_68640309279c819ea24ded9b9639c7330594799b59703b57', status='completed')
To excel in Module 1, which focuses on Docker and Terraform, here are some key strategies and tips based on common challenges faced by students:
1. **Understand Docker Basics**: Start by familiarizing yourself with the Docker ecosystem, including images, containers, and Docker Compose. Having a solid grasp of these concepts will help you avoid common pitfalls.
2. **Environment Setup**: Ensure you have a correctly set up local environment. This includes installing Docker and any necessary dependencies. For instance, if you encounter errors like `ModuleNotFoundError: No module named 'psycopg2'`, make sure to install it using:
```bash
pip install psycopg2-binary
```
or update as needed if you run into issues.
3. **Jupyter Notebooks**: When working in Jupyter notebooks, ensure you can access the necessary libraries. If you run into module errors, consider installing the required packages directly in the notebook, like so:
```python
!pip install psycopg2-binary
```
4. **Hands-On Practice**: Engage with the hands-on exercises provided in the module. Practicing with real commands and setups will cement your understanding.
5. **Ask Questions**: If you're stuck on a particular exercise or concept, don't hesitate to reach out to peers or instructors. Collaborating with others can enhance your learning experience.
6. **Review Code and Examples**: Go through the provided examples in the course and try to replicate them. This will give you practical insights into how to apply what you learn.
7. **Error Handling**: Learn to read error messages carefully. For instance, if you see errors about missing modules, check your installation commands. Many common issues arise from simple typos or assumptions about package availability.
If you keep these strategies in mind and actively engage with the materials, you'll improve your chances of success in Module 1.
What specific aspects of Module 1 are you finding challenging?
Docker and Terraform
function_call: ResponseFunctionToolCall(arguments='{"query":"Docker tips for Module 1"}', call_id='call_zcxJlRqgjfMjavLOgVY1FSj5', name='search', type='function_call', id='fc_6864031f32a0819e850cbe6692b6ab160594799b59703b57', status='completed')
function_call: ResponseFunctionToolCall(arguments='{"query":"Terraform tips for Module 1"}', call_id='call_4n2UHkf4UtPpg3XAM0V5WFfI', name='search', type='function_call', id='fc_6864031f61ec819eba1a01625d5a64430594799b59703b57', status='completed')
To do well in Module 1 focusing on Docker and Terraform, here are some targeted tips for both technologies:
### Docker Tips:
1. **Basic Understanding**: Ensure you have foundational knowledge of Docker, such as how to create and manage containers, and how to use Docker Compose for multi-container applications.
2. **Correct Installation**: If you encounter issues like `ModuleNotFoundError: No module named 'psycopg2'`, make sure that you're installing the required Python modules in your Docker environment. Update your Dockerfile to include:
```Dockerfile
RUN python -m pip install psycopg2-binary
```
3. **Working with Jupyter Notebooks**: When executing code in Jupyter, install necessary modules using:
```python
!pip install psycopg2-binary
```
4. **Consistent Environment**: Keep your development environment consistent with Docker. Always build and run your containers from the same local environment to minimize errors.
### Terraform Tips:
1. **Initialization**: When using Terraform, remember to run `terraform init` inside the correct working directory that contains your `.tf` files. If you run it outside, you'll receive errors about missing configurations.
2. **Permissions**: Pay attention to permissions in your Google Cloud project. If you encounter a `403` error related to `storage.buckets.create`, ensure you're using the correct Project ID and that the service account has the necessary permissions.
3. **Check System Time**: If you face issues with JWT tokens (like `invalid_grant` errors), it might be due to time desynchronization on your machine. Sync your system time using:
```bash
sudo hwclock -s
```
4. **Error Logging**: When encountering errors, rely on error messages to guide you. For example, if Terraform mentions a state lock issue, review the relevant documentation or GitHub issues related to your error.
### General Strategy:
- **Practice**: The more you practice using Docker and Terraform, the more comfortable you'll become with their commands and functionalities.
- **Documentation**: Refer to the official Docker and Terraform documentation for troubleshooting and advanced tips. This can be invaluable in resolving specific issues you may face.
If you need help with a specific Docker or Terraform command or concept, feel free to ask! What part of Docker or Terraform are you currently struggling with the most?
stop
Multiple tools
!wget https://raw.githubusercontent.com/alexeygrigorev/rag-agents-workshop/refs/heads/main/chat_assistant.pyOutput
--2025-07-01 17:50:28-- https://raw.githubusercontent.com/alexeygrigorev/rag-agents-workshop/refs/heads/main/chat_assistant.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.108.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3485 (3.4K) [text/plain]
Saving to: 'chat_assistant.py'
0K ... 100% 434K=0.008s
2025-07-01 17:50:28 (434 KB/s) - 'chat_assistant.py' saved [3485/3485]
def add_entry(question, answer):
doc = {
'question': question,
'text': answer,
'section': 'user added',
'course': 'data-engineering-zoomcamp'
}
index.append(doc)add_entry_description = {
"type": "function",
"name": "add_entry",
"description": "Add an entry to the FAQ database",
"parameters": {
"type": "object",
"properties": {
"question": {
"type": "string",
"description": "The question to be added to the FAQ database",
},
"answer": {
"type": "string",
"description": "The answer to the question",
}
},
"required": ["question", "answer"],
"additionalProperties": False
}
}import chat_assistant
tools = chat_assistant.Tools()
tools.add_tool(search, search_tool)Output
[{'type': 'function',
'name': 'search',
'description': 'Search the FAQ database',
'parameters': {'type': 'object',
'properties': {'query': {'type': 'string',
'description': 'Search query text to look up in the course FAQ.'}},
'required': ['query'],
'additionalProperties': False}}]tools.add_tool(add_entry, add_entry_description)tools.get_tools()Output
[{'type': 'function',
'name': 'search',
'description': 'Search the FAQ database',
'parameters': {'type': 'object',
'properties': {'query': {'type': 'string',
'description': 'Search query text to look up in the course FAQ.'}},
'required': ['query'],
'additionalProperties': False}},
{'type': 'function',
'name': 'add_entry',
'description': 'Add an entry to the FAQ database',
'parameters': {'type': 'object',
'properties': {'question': {'type': 'string',
'description': 'The question to be added to the FAQ database'},
'answer': {'type': 'string', 'description': 'The answer to the question'}},
'required': ['question', 'answer'],
'additionalProperties': False}}]developer_prompt = """
You're a course teaching assistant.
You're given a question from a course student and your task is to answer it.
Use FAQ if your own knowledge is not sufficient to answer the question.
At the end of each response, ask the user a follow up question based on your answer.
""".strip()
chat_interface = chat_assistant.ChatInterface()
chat = chat_assistant.ChatAssistant(
tools=tools,
developer_prompt=developer_prompt,
chat_interface=chat_interface,
client=client
)chat.run()Output
You: How do I do well in module 1?
<IPython.core.display.HTML object>
Function call: search({"query":"do well in module 1"})
ResponseFunctionToolCall(arguments='{"query":"do well in module 1"}', call_id='call_4iEnGse7DlYAvMy7ljBlaEDW', name='search', type='function_call', id='fc_6864051e058c81a3b2be4fc97f893c930d66a27d5be27c59', status='completed')
[
{
"text": "Issue:\ne\u2026\nSolution:\npip install psycopg2-binary\nIf you already have it, you might need to update it:\npip install psycopg2-binary --upgrade\nOther methods, if the above fails:\nif you are getting the \u201c ModuleNotFoundError: No module named 'psycopg2' \u201c error even after the above installation, then try updating conda using the command conda update -n base -c defaults conda. Or if you are using pip, then try updating it before installing the psycopg packages i.e\nFirst uninstall the psycopg package\nThen update conda or pip\nThen install psycopg again using pip.\nif you are still facing error with r pcycopg2 and showing pg_config not found then you will have to install postgresql. in MAC it is brew install postgresql",
"section": "Module 1: Docker and Terraform",
"question": "Postgres - ModuleNotFoundError: No module named 'psycopg2'",
"course": "data-engineering-zoomcamp",
"_id": 112
},
{
"text": "Following dbt with BigQuery on Docker readme.md, after `docker-compose build` and `docker-compose run dbt-bq-dtc init`, encountered error `ModuleNotFoundError: No module named 'pytz'`\nSolution:\nAdd `RUN python -m pip install --no-cache pytz` in the Dockerfile under `FROM --platform=$build_for python:3.9.9-slim-bullseye as base`",
"section": "Module 4: analytics engineering with dbt",
"question": "DBT - Error: No module named 'pytz' while setting up dbt with docker",
"course": "data-engineering-zoomcamp",
"_id": 299
},
{
"text": "create_engine('postgresql://root:root@localhost:5432/ny_taxi') I get the error \"TypeError: 'module' object is not callable\"\nSolution:\nconn_string = \"postgresql+psycopg://root:root@localhost:5432/ny_taxi\"\nengine = create_engine(conn_string)",
"section": "Module 1: Docker and Terraform",
"question": "Python - SQLALchemy - TypeError 'module' object is not callable",
"course": "data-engineering-zoomcamp",
"_id": 124
},
{
"text": "Error raised during the jupyter notebook\u2019s cell execution:\nengine = create_engine('postgresql://root:root@localhost:5432/ny_taxi').\nSolution: Need to install Python module \u201cpsycopg2\u201d. Can be installed by Conda or pip.",
"section": "Module 1: Docker and Terraform",
"question": "Python - SQLAlchemy - ModuleNotFoundError: No module named 'psycopg2'.",
"course": "data-engineering-zoomcamp",
"_id": 125
},
{
"text": "You need to look for the Py4J file and note the version of the filename. Once you know the version, you can update the export command accordingly, this is how you check yours:\n` ls ${SPARK_HOME}/python/lib/ ` and then you add it in the export command, mine was:\nexport PYTHONPATH=\u201d${SPARK_HOME}/python/lib/Py4J-0.10.9.5-src.zip:${PYTHONPATH}\u201d\nMake sure that the version under `${SPARK_HOME}/python/lib/` matches the filename of py4j or you will encounter `ModuleNotFoundError: No module named 'py4j'` while executing `import pyspark`.\nFor instance, if the file under `${SPARK_HOME}/python/lib/` was `py4j-0.10.9.3-src.zip`.\nThen the export PYTHONPATH statement above should be changed to `export PYTHONPATH=\"${SPARK_HOME}/python/lib/py4j-0.10.9.3-src.zip:$PYTHONPATH\"` appropriately.\nAdditionally, you can check for the version of \u2018py4j\u2019 of the spark you\u2019re using from here and update as mentioned above.\n~ Abhijit Chakraborty: Sometimes, even with adding the correct version of py4j might not solve the problem. Simply run pip install py4j and problem should be resolved.",
"section": "Module 5: pyspark",
"question": "Py4JJavaError - ModuleNotFoundError: No module named 'py4j'` while executing `import pyspark`",
"course": "data-engineering-zoomcamp",
"_id": 323
}
]
<IPython.core.display.HTML object>
To excel in Module 1, here are some tips based on the course content:
-
Understand the Basics: Ensure you grasp foundational concepts like Docker and Terraform, as these are essential for building a solid understanding in this module.
-
Practice Regularly: Engage with the practical assignments and exercises. Working hands-on will reinforce the concepts and tools covered.
-
Utilize Resources: Refer to the course materials, documentation, and any suggested readings. These are invaluable for deepening your comprehension.
-
Ask Questions: Don’t hesitate to reach out if you encounter difficulties or uncertainties. Engaging with peers or instructors can clarify your understanding.
-
Review Feedback: After completing sessions or tasks, take the time to review any feedback provided. This can guide your improvements in subsequent tasks.
-
Stay Organized: Keep your work organized, especially when handling multiple tools and configurations so you can easily trace back any errors that may arise.
Would you like more specific advice on any particular aspect of Module 1?
You: add this to the FAQ database
<IPython.core.display.HTML object>
Function call: add_entry({"question":"How do I do well in module 1?","an...)
ResponseFunctionToolCall(arguments='{"question":"How do I do well in module 1?","answer":"1. Understand the Basics: Ensure you grasp foundational concepts like Docker and Terraform.\\n2. Practice Regularly: Engage with practical assignments to reinforce concepts.\\n3. Utilize Resources: Refer to course materials, documentation, and suggested readings.\\n4. Ask Questions: Reach out if you encounter difficulties; engaging with peers or instructors can clarify your understanding.\\n5. Review Feedback: Take time to review feedback after completing tasks to guide improvements.\\n6. Stay Organized: Keep your work organized to easily trace back errors."}', call_id='call_bDeJ7ZqU9rKYPnSSPIgiIvV4', name='add_entry', type='function_call', id='fc_68640534ef8c81a389b44679839c6ce40d66a27d5be27c59', status='completed')
null
<IPython.core.display.HTML object>
I've added your question and answer to the FAQ database successfully!
Do you have any other questions or topics you'd like to explore further?
You: stop
Chat ended.
index.docs[-1]Output
{'question': 'How do I do well in module 1?',
'text': '1. Understand the Basics: Ensure you grasp foundational concepts like Docker and Terraform.\n2. Practice Regularly: Engage with practical assignments to reinforce concepts.\n3. Utilize Resources: Refer to course materials, documentation, and suggested readings.\n4. Ask Questions: Reach out if you encounter difficulties; engaging with peers or instructors can clarify your understanding.\n5. Review Feedback: Take time to review feedback after completing tasks to guide improvements.\n6. Stay Organized: Keep your work organized to easily trace back errors.',
'section': 'user added',
'course': 'data-engineering-zoomcamp'}indexOutput
<minsearch.append.AppendableIndex at 0x233d5173b90>
