# Week 9 labs — sources and changes

The course wrote both notebooks: `W9_practice_langchain_core.ipynb` (LangChain core patterns) and `W9_lab_rag.ipynb` (RAG over the EU AI Act). `lab.html` previews the lab's instructions and code.

## Document

- Regulation (EU) 2024/1689 (Artificial Intelligence Act), Official Journal of the European Union, L series, 12.7.2024, [ELI](http://data.europa.eu/eli/reg/2024/1689/oj).
  - The course converted the EUR-Lex HTML into Markdown at `labs/data/eu_ai_act.md`. Each chapter is a `#` heading, and each article or annex is a `##` heading.
  - Recitals and footnotes are omitted, and only the Official Journal text is authentic.
  - EUR-Lex permits reuse with acknowledgment of the source (Commission Decision 2011/833/EU). The notebook downloads the file at runtime.

## Code patterns

- The lab splits, embeds, stores, and retrieves the way the LangChain documentation does:
  - `MarkdownHeaderTextSplitter` and `RecursiveCharacterTextSplitter`
  - `OpenAIEmbeddings`, `InMemoryVectorStore`, and `similarity_search`
  - See the [LangChain RAG documentation](https://docs.langchain.com/oss/python/langchain/rag) and the [text splitter documentation](https://docs.langchain.com/oss/python/integrations/splitters).
- Retrieval and generation are two separate, visible steps: `retrieve()`, then an input built from the passages. Week 10 turns the same search into a tool of a `create_agent` agent.
- The practice notebook repeats the patterns of the Week 5 practice notebook with LangChain objects:
  - `init_chat_model`, message objects, `with_structured_output`
  - `@tool` with `bind_tools`, the agent loop, `create_agent`

## Packages

`langchain==1.4.4`, `langchain-openai==1.7.0`, `langgraph==1.2.14`, `langchain-text-splitters==1.1.3`. The models are `gpt-4.1` and `text-embedding-3-small`. No LangSmith account is needed.
