andre-fichel commited on
Commit
d62fb85
1 Parent(s): 14e0861

AIE2 midterm submission

Browse files
Dockerfile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10.13
2
+ RUN useradd -m -u 1000 user
3
+ USER user
4
+ ENV HOME=/home/user \
5
+ PATH=/home/user/.local/bin:$PATH
6
+ WORKDIR $HOME/app
7
+ COPY --chown=user ./requirements.txt $HOME/app/requirements.txt
8
+ RUN pip install -r requirements.txt
9
+ COPY --chown=user . $HOME/app
10
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 fichel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
app.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import dependencies
2
+ import os
3
+ import requests
4
+ from operator import itemgetter
5
+ import chainlit as cl
6
+ from llama_parse import LlamaParse
7
+ from llama_parse.utils import ResultType
8
+ from llama_index.core import SimpleDirectoryReader
9
+ from langchain.text_splitter import (
10
+ RecursiveCharacterTextSplitter,
11
+ MarkdownHeaderTextSplitter,
12
+ )
13
+ from langchain.schema.runnable.config import RunnableConfig
14
+ from langchain_community.vectorstores import Qdrant
15
+ from langchain_community.document_loaders import DirectoryLoader
16
+ from langchain_openai import ChatOpenAI
17
+ from langchain_openai.embeddings import OpenAIEmbeddings
18
+ from langchain_core.prompts import ChatPromptTemplate
19
+ from langchain_core.runnables import RunnablePassthrough
20
+ from langchain_core.output_parsers import StrOutputParser
21
+ from qdrant_client import QdrantClient
22
+
23
+ # load keys and variables
24
+ from dotenv import load_dotenv
25
+
26
+ load_dotenv()
27
+
28
+ os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
29
+ os.environ["LLAMA_CLOUD_API_KEY"] = os.getenv("LLAMA_CLOUD_API_KEY")
30
+ QDRANT_URL = os.getenv("QDRANT_URL")
31
+ QDRANT_API_KEY = os.getenv("QDRANT_API_KEY")
32
+
33
+ # pdf url
34
+ URL = "https://d18rn0p25nwr6d.cloudfront.net/CIK-0001326801/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf"
35
+
36
+ # parse instructions
37
+ PARSING_INSTRUCTION = """The provided document is an annual report filed by Meta Platforms, Inc. with the Securities and Exchange Commission (SEC).
38
+ This form provides detailed financial information about the company's performance for a specific year.
39
+ It includes financial statements, management discussion and analysis, and other relevant disclosures required by the SEC.
40
+ It contains many tables and some signature pages.
41
+
42
+ Replace the signatures with tables containing the headers for each element.
43
+ """
44
+
45
+ # rag prompt
46
+ RAG_PROMPT = """
47
+ CONTEXT:
48
+ {context}
49
+
50
+ QUERY:
51
+ {question}
52
+
53
+ The provided context is an annual report filed by Meta Platforms, Inc. with the Securities and Exchange Commission (SEC).
54
+ This form provides detailed financial information about the company's performance for a specific year.
55
+ It includes financial statements, management discussion and analysis, and other relevant disclosures required by the SEC.
56
+ It contains many tables and some signature pages. All members of the board need to sign the document.
57
+
58
+ Answer the query above only using the context provided. If you don't know the answer, simply say 'I don't know'.
59
+ """
60
+
61
+
62
+ def create_new_vectorstore(collection_name, embeddings) -> Qdrant:
63
+ data_file = "./data/output.md"
64
+ # Check if the file exists
65
+ if os.path.exists(data_file):
66
+ print("The 10-K form has been parsed already. Using the cached version.")
67
+ else:
68
+ print("Cache is empty. Parsing will begin.")
69
+ parse_10K_file()
70
+
71
+ # load the document
72
+ loader = DirectoryLoader(path="data/", glob="**/*.md", show_progress=True)
73
+ documents = loader.load()
74
+
75
+ # split the document into chunks
76
+
77
+ # split markdown headers
78
+ headers_to_split_on = [
79
+ ("#", "Header 1"),
80
+ ("##", "Header 2"),
81
+ ("###", "Header 3"),
82
+ ]
83
+
84
+ md_text_splitter = MarkdownHeaderTextSplitter(
85
+ headers_to_split_on=headers_to_split_on, strip_headers=False
86
+ )
87
+
88
+ md_splits = md_text_splitter.split_text(documents[0].page_content)
89
+
90
+ # recursive character text splitter
91
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, chunk_overlap=100)
92
+ docs = text_splitter.split_documents(md_splits)
93
+
94
+ # create the vectorstore
95
+ qdrant_vector_store = Qdrant.from_documents(
96
+ documents=docs,
97
+ embedding=embeddings,
98
+ url=QDRANT_URL,
99
+ api_key=QDRANT_API_KEY,
100
+ collection_name=collection_name,
101
+ )
102
+
103
+ return qdrant_vector_store
104
+
105
+
106
+ def get_vectorstore(client, collection_name, embeddings) -> Qdrant:
107
+
108
+ try:
109
+ vector_store = Qdrant(
110
+ client=client,
111
+ collection_name=collection_name,
112
+ embeddings=embeddings,
113
+ )
114
+ print(vector_store.embeddings)
115
+ except:
116
+ # create the vectorstore
117
+ vector_store = create_new_vectorstore(collection_name, embeddings)
118
+
119
+ return vector_store
120
+
121
+
122
+ def parse_10K_file() -> None:
123
+
124
+ # Create the data directory if it doesn't exist
125
+ data_dir = "data"
126
+ os.makedirs(data_dir, exist_ok=True)
127
+
128
+ # Check if the file already exists
129
+ file_path = os.path.join(data_dir, "Meta_10k.pdf")
130
+ if not os.path.exists(file_path):
131
+ # Download the file
132
+ url = URL
133
+ response = requests.get(url)
134
+
135
+ # Save the file to the data directory
136
+ with open(file_path, "wb") as file:
137
+ file.write(response.content)
138
+ print("File downloaded successfully.")
139
+ else:
140
+ print("File already exists. Skipping download.")
141
+
142
+ # setup parser
143
+ parser = LlamaParse(
144
+ result_type=ResultType.MD, parsing_instruction=PARSING_INSTRUCTION
145
+ )
146
+
147
+ # load and parse the documet
148
+ file_extractor = {".pdf": parser}
149
+ llama_parse_documents = SimpleDirectoryReader(
150
+ input_files=["data/Meta_10k.pdf"], file_extractor=file_extractor
151
+ ).load_data()
152
+
153
+ # save markdown file
154
+ data_file = "./data/output.md"
155
+ with open(data_file, "a") as f:
156
+ for doc in llama_parse_documents:
157
+ f.write(doc.text + "\n")
158
+
159
+
160
+ @cl.on_chat_start
161
+ async def start() -> None:
162
+ # instantiate embeddings
163
+ embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
164
+
165
+ # get vectorstore
166
+ client = QdrantClient(
167
+ QDRANT_URL,
168
+ api_key=QDRANT_API_KEY, # For Qdrant Cloud, None for local instance
169
+ )
170
+ collection_name = "meta_10k"
171
+ qdrant_vectorstore = get_vectorstore(client, collection_name, embeddings)
172
+
173
+ # setup our retriever
174
+ qdrant_retriever = qdrant_vectorstore.as_retriever()
175
+
176
+ # setup rag prompt
177
+ rag_prompt = ChatPromptTemplate.from_template(RAG_PROMPT)
178
+
179
+ # setup the rag chain
180
+ chat_model = ChatOpenAI(model="gpt-3.5-turbo")
181
+
182
+ rag_chain = (
183
+ {
184
+ "question": itemgetter("question"),
185
+ "context": itemgetter("question") | qdrant_retriever,
186
+ }
187
+ | RunnablePassthrough().assign(context=itemgetter("context"))
188
+ | {
189
+ "response": rag_prompt | chat_model | StrOutputParser(),
190
+ "context": itemgetter("context"),
191
+ }
192
+ )
193
+
194
+ cl.user_session.set("rag_chain", rag_chain)
195
+ await cl.Message(
196
+ author="Assistant", content="Hi, I'm your Meta 10K Assistant! How can I help?"
197
+ ).send()
198
+
199
+
200
+ @cl.on_message
201
+ async def main(message: cl.Message) -> None:
202
+ chain = cl.user_session.get("rag_chain")
203
+ cb = cl.AsyncLangchainCallbackHandler()
204
+ cb.answer_reached = True
205
+ # res=await chain.acall(message, callbacks=[cb])
206
+ res = await chain.ainvoke(
207
+ {"question": message.content}, config=RunnableConfig(callbacks=[cb])
208
+ )
209
+ print(f"response: {res}")
210
+ answer = res["response"]
211
+
212
+ await cl.Message(author="Assistant", content=answer).send()
chainlit.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Meta 10-K 2023 ChatBot 🤖
2
+
3
+ Welcome to the Meta 10-K 2023 Chatbot! You can ask me any questions you want about Meta's 10-K Form from 2023!.
data/output.md ADDED
The diff for this file is too large to render. See raw diff
 
meta_10k/.lock ADDED
@@ -0,0 +1 @@
 
 
1
+ tmp lock file
meta_10k/meta.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"collections": {}, "aliases": {}}
notebooks/AIE2_midterm.ipynb ADDED
@@ -0,0 +1,909 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "collapsed_sections": [
8
+ "QojysEo6Soqb",
9
+ "8tpilHaaSoSg",
10
+ "p0BhZDfbk2KT"
11
+ ]
12
+ },
13
+ "kernelspec": {
14
+ "name": "python3",
15
+ "display_name": "Python 3"
16
+ },
17
+ "language_info": {
18
+ "name": "python"
19
+ }
20
+ },
21
+ "cells": [
22
+ {
23
+ "cell_type": "markdown",
24
+ "source": [
25
+ "# Midterm Certification Challenge: Building and Deploying a RAG Application\n",
26
+ "DUE DATE: Before 4:00 PM PT on May 2 (before next Thursday's class!)\n",
27
+ "\n",
28
+ "You are to record the total time it takes you to complete\n",
29
+ "\n",
30
+ "You have access to all boiler-plate code from the course, and we highly encourage you to leverage it!\n",
31
+ "\n",
32
+ "**Deliverables:**\n",
33
+ "\n",
34
+ "**Build 🏗️**\n",
35
+ "\n",
36
+ "* Data: Meta 10-k Filings\n",
37
+ "* LLM: OpenAI GPT-3.5-turbo\n",
38
+ "* Embedding Model: text-3-embedding small\n",
39
+ "* Infrastructure: LangChain or LlamaIndex (you choose)\n",
40
+ "* Vector Store: Qdrant\n",
41
+ "* Deployment: Chainlit, Hugging Face\n",
42
+ "**Ship 🚢**\n",
43
+ "\n",
44
+ "* Evaluate your answers to the following questions\n",
45
+ "\"What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\"\n",
46
+ "\"Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\"\n",
47
+ "* Record <10 min loom video walkthrough\n",
48
+ "$$ Extra Credit: Baseline retrieval performance w/ RAGAS, change something about your RAG system to improve it, then show the improvement quantitatively!\n",
49
+ "\n",
50
+ "**Share 🚀**\n",
51
+ "* Share lessons not yet learned in #aie2-general"
52
+ ],
53
+ "metadata": {
54
+ "id": "uDsowVwcRyZ8"
55
+ }
56
+ },
57
+ {
58
+ "cell_type": "markdown",
59
+ "source": [
60
+ "## Install Dependencies"
61
+ ],
62
+ "metadata": {
63
+ "id": "QojysEo6Soqb"
64
+ }
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "source": [
69
+ "import nest_asyncio\n",
70
+ "\n",
71
+ "nest_asyncio.apply()"
72
+ ],
73
+ "metadata": {
74
+ "id": "hizlCdZeh1i7"
75
+ },
76
+ "execution_count": 1,
77
+ "outputs": []
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 5,
82
+ "metadata": {
83
+ "id": "BXSRaRN2RixC"
84
+ },
85
+ "outputs": [],
86
+ "source": [
87
+ "!pip install llama-parse llama_index -qU"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "source": [
93
+ "!pip install -qU langchain langchain-core langchain-community langchain-openai unstructured"
94
+ ],
95
+ "metadata": {
96
+ "id": "uZJ6AIUs3c4j"
97
+ },
98
+ "execution_count": 6,
99
+ "outputs": []
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "source": [
104
+ "!pip install -qU qdrant-client"
105
+ ],
106
+ "metadata": {
107
+ "id": "5quBcn6K39hF"
108
+ },
109
+ "execution_count": 7,
110
+ "outputs": []
111
+ },
112
+ {
113
+ "cell_type": "markdown",
114
+ "source": [
115
+ "## Set Environment Variables"
116
+ ],
117
+ "metadata": {
118
+ "id": "8tpilHaaSoSg"
119
+ }
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "source": [
124
+ "import os\n",
125
+ "from getpass import getpass\n",
126
+ "\n",
127
+ "# set openai key\n",
128
+ "os.environ[\"OPENAI_API_KEY\"] = getpass(\"OpenAI API Key:\")"
129
+ ],
130
+ "metadata": {
131
+ "colab": {
132
+ "base_uri": "https://localhost:8080/"
133
+ },
134
+ "id": "AfvigvZfTXjX",
135
+ "outputId": "b6c3f8e5-7701-494f-e6e3-85fed9471d5f"
136
+ },
137
+ "execution_count": 13,
138
+ "outputs": [
139
+ {
140
+ "name": "stdout",
141
+ "output_type": "stream",
142
+ "text": [
143
+ "OpenAI API Key:··········\n"
144
+ ]
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "source": [
151
+ "# set llama cloud key\n",
152
+ "os.environ[\"LLAMA_CLOUD_API_KEY\"] = getpass(\"Llama Cloud API Key:\")"
153
+ ],
154
+ "metadata": {
155
+ "colab": {
156
+ "base_uri": "https://localhost:8080/"
157
+ },
158
+ "id": "4WVa_areeqb4",
159
+ "outputId": "4433e2ce-9a37-4b5d-975d-9a310710708d"
160
+ },
161
+ "execution_count": 9,
162
+ "outputs": [
163
+ {
164
+ "name": "stdout",
165
+ "output_type": "stream",
166
+ "text": [
167
+ "Llama Cloud API Key:··········\n"
168
+ ]
169
+ }
170
+ ]
171
+ },
172
+ {
173
+ "cell_type": "markdown",
174
+ "source": [
175
+ "## Download the Data"
176
+ ],
177
+ "metadata": {
178
+ "id": "p0BhZDfbk2KT"
179
+ }
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "source": [
184
+ "# download the data\n",
185
+ "!mkdir 'data'\n",
186
+ "!wget 'https://d18rn0p25nwr6d.cloudfront.net/CIK-0001326801/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf' -O 'data/Meta_10k.pdf'"
187
+ ],
188
+ "metadata": {
189
+ "colab": {
190
+ "base_uri": "https://localhost:8080/"
191
+ },
192
+ "id": "XJbBJ17zieee",
193
+ "outputId": "1bc31bbd-7139-4f29-ef17-2a591815d76f"
194
+ },
195
+ "execution_count": 10,
196
+ "outputs": [
197
+ {
198
+ "output_type": "stream",
199
+ "name": "stdout",
200
+ "text": [
201
+ "--2024-05-02 18:27:08-- https://d18rn0p25nwr6d.cloudfront.net/CIK-0001326801/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf\n",
202
+ "Resolving d18rn0p25nwr6d.cloudfront.net (d18rn0p25nwr6d.cloudfront.net)... 18.154.131.210, 18.154.131.173, 18.154.131.90, ...\n",
203
+ "Connecting to d18rn0p25nwr6d.cloudfront.net (d18rn0p25nwr6d.cloudfront.net)|18.154.131.210|:443... connected.\n",
204
+ "HTTP request sent, awaiting response... 200 OK\n",
205
+ "Length: 2481466 (2.4M) [application/pdf]\n",
206
+ "Saving to: ‘data/Meta_10k.pdf’\n",
207
+ "\n",
208
+ "\rdata/Meta_10k.pdf 0%[ ] 0 --.-KB/s \rdata/Meta_10k.pdf 100%[===================>] 2.37M --.-KB/s in 0.05s \n",
209
+ "\n",
210
+ "2024-05-02 18:27:08 (47.1 MB/s) - ‘data/Meta_10k.pdf’ saved [2481466/2481466]\n",
211
+ "\n"
212
+ ]
213
+ }
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "markdown",
218
+ "source": [
219
+ "## RAG with Llama Parse + LangChain RecursiveCharacterTextSplitter"
220
+ ],
221
+ "metadata": {
222
+ "id": "j9I3akvG2AjJ"
223
+ }
224
+ },
225
+ {
226
+ "cell_type": "markdown",
227
+ "source": [
228
+ "First, we'll parse the document using Llama Parse. Then we'll save the llama_parse markdown document so we can use it later."
229
+ ],
230
+ "metadata": {
231
+ "id": "QiAk6mbE6E4L"
232
+ }
233
+ },
234
+ {
235
+ "cell_type": "code",
236
+ "source": [
237
+ "# import dependencies\n",
238
+ "from llama_parse import LlamaParse\n",
239
+ "from llama_index.core import SimpleDirectoryReader\n",
240
+ "\n",
241
+ "parsing_instruction = \"\"\"The provided document is an annual report filed by Meta Platforms, Inc. with the Securities and Exchange Commission (SEC).\n",
242
+ "This form provides detailed financial information about the company's performance for a specific year.\n",
243
+ "It includes financial statements, management discussion and analysis, and other relevant disclosures required by the SEC.\n",
244
+ "It contains many tables and some signature pages.\n",
245
+ "\n",
246
+ "Replace the signatures with tables containing the headers for each element.\n",
247
+ "\"\"\"\n",
248
+ "\n",
249
+ "# setup parser\n",
250
+ "parser = LlamaParse(\n",
251
+ " result_type=\"markdown\",\n",
252
+ " parsing_instruction=parsing_instruction\n",
253
+ ")\n",
254
+ "\n",
255
+ "# load and parse the documet\n",
256
+ "file_extractor = {\".pdf\": parser}\n",
257
+ "llama_parse_documents = SimpleDirectoryReader(\n",
258
+ " input_files=['data/Meta_10k.pdf'],\n",
259
+ " file_extractor=file_extractor\n",
260
+ ").load_data()\n",
261
+ "\n",
262
+ "# save markdown file\n",
263
+ "data_file = \"./data/output.md\"\n",
264
+ "with open(data_file, \"a\") as f:\n",
265
+ " for doc in llama_parse_documents:\n",
266
+ " f.write(doc.text + '\\n')"
267
+ ],
268
+ "metadata": {
269
+ "id": "Q9LXiA4U12aM",
270
+ "colab": {
271
+ "base_uri": "https://localhost:8080/"
272
+ },
273
+ "outputId": "64b30010-24a3-4a5f-a834-e6978857657f"
274
+ },
275
+ "execution_count": 71,
276
+ "outputs": [
277
+ {
278
+ "output_type": "stream",
279
+ "name": "stdout",
280
+ "text": [
281
+ "Started parsing the file under job_id f27fcb88-f758-4d41-b1ab-d38b8daf6754\n",
282
+ "...."
283
+ ]
284
+ }
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "markdown",
289
+ "source": [
290
+ "Now we'll setup the langchain RAG with Qdrant"
291
+ ],
292
+ "metadata": {
293
+ "id": "JlwmRXZi6PYu"
294
+ }
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "source": [
299
+ "# import dependencies\n",
300
+ "from langchain.text_splitter import RecursiveCharacterTextSplitter, MarkdownHeaderTextSplitter\n",
301
+ "from langchain_community.vectorstores import Qdrant\n",
302
+ "from langchain_community.document_loaders import DirectoryLoader\n",
303
+ "from langchain_openai.embeddings import OpenAIEmbeddings\n",
304
+ "\n",
305
+ "# load the document\n",
306
+ "loader = DirectoryLoader(path='data/', glob=\"**/*.md\", show_progress=True)\n",
307
+ "documents = loader.load()\n",
308
+ "\n",
309
+ "# split the document into chunks\n",
310
+ "\n",
311
+ "# split markdown headers\n",
312
+ "headers_to_split_on = [\n",
313
+ " (\"#\", \"Header 1\"),\n",
314
+ " (\"##\", \"Header 2\"),\n",
315
+ " (\"###\", \"Header 3\"),\n",
316
+ "]\n",
317
+ "\n",
318
+ "md_text_splitter = MarkdownHeaderTextSplitter(\n",
319
+ " headers_to_split_on=headers_to_split_on,\n",
320
+ " strip_headers = False\n",
321
+ ")\n",
322
+ "\n",
323
+ "md_splits = md_text_splitter.split_text(documents[0].page_content)\n",
324
+ "\n",
325
+ "# recursive character text splitter\n",
326
+ "text_splitter = RecursiveCharacterTextSplitter(chunk_size=2500, chunk_overlap=100)\n",
327
+ "docs = text_splitter.split_documents(md_splits)\n",
328
+ "\n",
329
+ "# instantiate embeddings\n",
330
+ "embeddings = OpenAIEmbeddings(model=\"text-embedding-3-small\")\n",
331
+ "\n",
332
+ "# create the vectorstore\n",
333
+ "qdrant_vector_store = Qdrant.from_documents(\n",
334
+ " documents=docs,\n",
335
+ " embedding=embeddings,\n",
336
+ " location=\":memory:\",\n",
337
+ " collection_name=\"meta_10k\"\n",
338
+ ")\n",
339
+ "\n",
340
+ "# setup our retriever\n",
341
+ "qdrant_retriever = qdrant_vector_store.as_retriever()"
342
+ ],
343
+ "metadata": {
344
+ "colab": {
345
+ "base_uri": "https://localhost:8080/"
346
+ },
347
+ "id": "Mkq3v2XX5oY0",
348
+ "outputId": "18c9039b-3f22-44b8-a830-2f64c9d8e59b"
349
+ },
350
+ "execution_count": 83,
351
+ "outputs": [
352
+ {
353
+ "output_type": "stream",
354
+ "name": "stderr",
355
+ "text": [
356
+ "100%|██████████| 1/1 [00:16<00:00, 16.71s/it]\n"
357
+ ]
358
+ }
359
+ ]
360
+ },
361
+ {
362
+ "cell_type": "markdown",
363
+ "source": [
364
+ "Next, we'll setup the RAG Prompt."
365
+ ],
366
+ "metadata": {
367
+ "id": "n5l5oZwq_1zq"
368
+ }
369
+ },
370
+ {
371
+ "cell_type": "code",
372
+ "source": [
373
+ "from langchain_core.prompts import ChatPromptTemplate\n",
374
+ "\n",
375
+ "RAG_PROMPT = \"\"\"\n",
376
+ "CONTEXT:\n",
377
+ "{context}\n",
378
+ "\n",
379
+ "QUERY:\n",
380
+ "{question}\n",
381
+ "\n",
382
+ "The provided context is an annual report filed by Meta Platforms, Inc. with the Securities and Exchange Commission (SEC).\n",
383
+ "This form provides detailed financial information about the company's performance for a specific year.\n",
384
+ "It includes financial statements, management discussion and analysis, and other relevant disclosures required by the SEC.\n",
385
+ "It contains many tables and some signature pages. All members of the board need to sign the document.\n",
386
+ "\n",
387
+ "Answer the query above only using the context provided. If you don't know the answer, simply say 'I don't know'.\n",
388
+ "\"\"\"\n",
389
+ "\n",
390
+ "rag_prompt = ChatPromptTemplate.from_template(RAG_PROMPT)"
391
+ ],
392
+ "metadata": {
393
+ "id": "MFvFEItd_4nq"
394
+ },
395
+ "execution_count": 84,
396
+ "outputs": []
397
+ },
398
+ {
399
+ "cell_type": "markdown",
400
+ "source": [
401
+ "Finally, we create our chain..."
402
+ ],
403
+ "metadata": {
404
+ "id": "SlmhFU4DACib"
405
+ }
406
+ },
407
+ {
408
+ "cell_type": "code",
409
+ "source": [
410
+ "from operator import itemgetter\n",
411
+ "from langchain_core.runnables import RunnablePassthrough\n",
412
+ "from langchain_core.output_parsers import StrOutputParser\n",
413
+ "from langchain_openai import ChatOpenAI\n",
414
+ "\n",
415
+ "chat_model = ChatOpenAI(model=\"gpt-3.5-turbo\")\n",
416
+ "\n",
417
+ "rag_chain = (\n",
418
+ " {\"question\": itemgetter(\"question\"), \"context\": itemgetter(\"question\") | qdrant_retriever}\n",
419
+ " | RunnablePassthrough().assign(context=itemgetter(\"context\"))\n",
420
+ " | {\"response\":rag_prompt | chat_model | StrOutputParser(), \"context\": itemgetter(\"context\")}\n",
421
+ ")"
422
+ ],
423
+ "metadata": {
424
+ "id": "ptOBMYQiAHKG"
425
+ },
426
+ "execution_count": 85,
427
+ "outputs": []
428
+ },
429
+ {
430
+ "cell_type": "markdown",
431
+ "source": [
432
+ "## Query the Meta 10-K Form"
433
+ ],
434
+ "metadata": {
435
+ "id": "IYpC7OUInDBU"
436
+ }
437
+ },
438
+ {
439
+ "cell_type": "markdown",
440
+ "source": [
441
+ "Great, time to query the Form!"
442
+ ],
443
+ "metadata": {
444
+ "id": "tAhPVqoOnMFv"
445
+ }
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "source": [
450
+ "# query the rag_chain\n",
451
+ "query1 = \"What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\"\n",
452
+ "response = rag_chain.invoke({\"question\": query1})\n",
453
+ "print(response['response'])"
454
+ ],
455
+ "metadata": {
456
+ "colab": {
457
+ "base_uri": "https://localhost:8080/"
458
+ },
459
+ "outputId": "83d6a53e-12d0-480c-be60-20cff724ca0e",
460
+ "id": "tO61pDX012aN"
461
+ },
462
+ "execution_count": 87,
463
+ "outputs": [
464
+ {
465
+ "output_type": "stream",
466
+ "name": "stdout",
467
+ "text": [
468
+ "The total value of 'Cash and cash equivalents' as of December 31, 2023, was $41,862 million.\n"
469
+ ]
470
+ }
471
+ ]
472
+ },
473
+ {
474
+ "cell_type": "code",
475
+ "source": [
476
+ "for context in response['context']:\n",
477
+ " print('======== CONTEXT ========')\n",
478
+ " print(context.page_content)"
479
+ ],
480
+ "metadata": {
481
+ "colab": {
482
+ "base_uri": "https://localhost:8080/"
483
+ },
484
+ "id": "v03JzLwwjIBm",
485
+ "outputId": "4ad79d63-8817-4433-e9f6-f3969d8d1207"
486
+ },
487
+ "execution_count": 88,
488
+ "outputs": [
489
+ {
490
+ "output_type": "stream",
491
+ "name": "stdout",
492
+ "text": [
493
+ "======== CONTEXT ========\n",
494
+ "Fair Value Measurement at Reporting Date Using\n",
495
+ "|Description|December 31, 2023|Quoted Prices in Active Markets for Identical Assets (Level 1)|Significant Observable Inputs (Level 2)|Significant Unobservable Inputs (Level 3)|\n",
496
+ "|---|---|---|---|---|\n",
497
+ "|Cash|$6,265| | | |\n",
498
+ "|Cash equivalents: Money market funds|$32,910|$32,910| | |\n",
499
+ "|Cash equivalents: U.S. government and agency securities|$2,206|$2,206| | |\n",
500
+ "|Cash equivalents: Time deposits|$261| |$261| |\n",
501
+ "|Cash equivalents: Corporate debt securities|$220| |$220| |\n",
502
+ "|Total cash and cash equivalents|$41,862|$35,116|$481| |\n",
503
+ "|Marketable securities: U.S. government securities|$8,439|$8,439| | |\n",
504
+ "|Marketable securities: U.S. government agency securities|$3,498|$3,498| | |\n",
505
+ "|Marketable securities: Corporate debt securities|$11,604| |$11,604| |\n",
506
+ "|Total marketable securities|$23,541|$11,937|$11,604| |\n",
507
+ "|Restricted cash equivalents|$857|$857| | |\n",
508
+ "|Other assets|$101| | |$101|\n",
509
+ "|Total|$66,361|$47,910|$12,085|$101|\n",
510
+ "\n",
511
+ "107\n",
512
+ "\n",
513
+ "Meta Platforms, Inc. - Annual Report\n",
514
+ "\n",
515
+ "Table of Contents\n",
516
+ "\n",
517
+ "Fair Value Measurement at Reporting Date Using\n",
518
+ "\n",
519
+ "Description December 31, 2022 Quoted Prices in Active Markets for Identical Assets (Level 1) Significant Other Observable Inputs (Level 2) Significant Unobservable Inputs (Level 3) Cash $6,176 Cash equivalents: Money market funds $8,305 $8,305 Cash equivalents: U.S. government and agency securities $16 $16 Cash equivalents: Time deposits $156 $156 Cash equivalents: Corporate debt securities $28 $28 Total cash and cash equivalents $14,681 $8,321 $184 Marketable securities: U.S. government securities $8,708 $8,708 Marketable securities: U.S. government agency securities $4,989 $4,989 Marketable securities: Corporate debt securities $12,335 $12,335 Marketable securities: Marketable equity securities $25 $25 Total marketable securities $26,057 $13,722 $12,335 Restricted cash equivalents $583 $583 Other assets $157 $157 Total $41,478 $22,626 $12,519 $157\n",
520
+ "\n",
521
+ "Unrealized Losses\n",
522
+ "\n",
523
+ "The following tables summarize our available-for-sale marketable debt securities and cash equivalents with unrealized losses as of December 31, 2023 and 2022, aggregated by major security type and the length of time that individual securities have been in a continuous loss position (in millions):\n",
524
+ "\n",
525
+ "December 31, 2023\n",
526
+ "\n",
527
+ "Less than 12 months 12 months or greater Total U.S. government securities $336 $7,041 $7,377 U.S. government agency securities $71 $3,225 $3,296 Corporate debt securities $647 $10,125 $10,772 Total $1,054 $20,391 $21,445\n",
528
+ "======== CONTEXT ========\n",
529
+ "Fair Value Measurement at Reporting Date Using\n",
530
+ "|Description|December 31, 2023|Quoted Prices in Active Markets for Identical Assets (Level 1)|Significant Observable Inputs (Level 2)|Significant Unobservable Inputs (Level 3)|\n",
531
+ "|---|---|---|---|---|\n",
532
+ "|Cash|$6,265| | | |\n",
533
+ "|Cash equivalents: Money market funds|$32,910|$32,910| | |\n",
534
+ "|Cash equivalents: U.S. government and agency securities|$2,206|$2,206| | |\n",
535
+ "|Cash equivalents: Time deposits|$261| |$261| |\n",
536
+ "|Cash equivalents: Corporate debt securities|$220| |$220| |\n",
537
+ "|Total cash and cash equivalents|$41,862|$35,116|$481| |\n",
538
+ "|Marketable securities: U.S. government securities|$8,439|$8,439| | |\n",
539
+ "|Marketable securities: U.S. government agency securities|$3,498|$3,498| | |\n",
540
+ "|Marketable securities: Corporate debt securities|$11,604| |$11,604| |\n",
541
+ "|Total marketable securities|$23,541|$11,937|$11,604| |\n",
542
+ "|Restricted cash equivalents|$857|$857| | |\n",
543
+ "|Other assets|$101| | |$101|\n",
544
+ "|Total|$66,361|$47,910|$12,085|$101|\n",
545
+ "\n",
546
+ "107\n",
547
+ "\n",
548
+ "Meta Platforms, Inc. - Annual Report\n",
549
+ "\n",
550
+ "Table of Contents\n",
551
+ "\n",
552
+ "Fair Value Measurement at Reporting Date Using\n",
553
+ "\n",
554
+ "Description December 31, 2022 Quoted Prices in Active Markets for Identical Assets (Level 1) Significant Other Observable Inputs (Level 2) Significant Unobservable Inputs (Level 3) Cash $6,176 Cash equivalents: Money market funds $8,305 $8,305 Cash equivalents: U.S. government and agency securities $16 $16 Cash equivalents: Time deposits $156 $156 Cash equivalents: Corporate debt securities $28 $28 Total cash and cash equivalents $14,681 $8,321 $184 Marketable securities: U.S. government securities $8,708 $8,708 Marketable securities: U.S. government agency securities $4,989 $4,989 Marketable securities: Corporate debt securities $12,335 $12,335 Marketable securities: Marketable equity securities $25 $25 Total marketable securities $26,057 $13,722 $12,335 Restricted cash equivalents $583 $583 Other assets $157 $157 Total $41,478 $22,626 $12,519 $157\n",
555
+ "\n",
556
+ "Unrealized Losses\n",
557
+ "\n",
558
+ "The following tables summarize our available-for-sale marketable debt securities and cash equivalents with unrealized losses as of December 31, 2023 and 2022, aggregated by major security type and the length of time that individual securities have been in a continuous loss position (in millions):\n",
559
+ "\n",
560
+ "December 31, 2023\n",
561
+ "\n",
562
+ "Less than 12 months 12 months or greater Total U.S. government securities $336 $7,041 $7,377 U.S. government agency securities $71 $3,225 $3,296 Corporate debt securities $647 $10,125 $10,772 Total $1,054 $20,391 $21,445\n",
563
+ "======== CONTEXT ========\n",
564
+ "The following tables summarize our assets measured at fair value on a recurring basis and the classification by level of input within the fair value hierarchy (in millions):\n",
565
+ "\n",
566
+ "Fair Value Measurement at Reporting Date Using\n",
567
+ "|Description|December 31, 2023|Quoted Prices in Active Markets for Identical Assets (Level 1)|Significant Other Observable Inputs (Level 2)|Significant Unobservable Inputs (Level 3)|\n",
568
+ "|---|---|---|---|---|\n",
569
+ "|Cash|$6,265| | | |\n",
570
+ "|Cash equivalents: Money market funds|$32,910|$32,910| | |\n",
571
+ "|Cash equivalents: U.S. government and agency securities|$2,206|$2,206| | |\n",
572
+ "|Cash equivalents: Time deposits|$261| |$261| |\n",
573
+ "|Cash equivalents: Corporate debt securities|$220| |$220| |\n",
574
+ "|Total cash and cash equivalents|$41,862|$35,116|$481| |\n",
575
+ "|Marketable securities: U.S. government securities|$8,439|$8,439| | |\n",
576
+ "|Marketable securities: U.S. government agency securities|$3,498|$3,498| | |\n",
577
+ "|Marketable securities: Corporate debt securities|$11,604| |$11,604| |\n",
578
+ "|Total marketable securities|$23,541|$11,937|$11,604| |\n",
579
+ "|Restricted cash equivalents|$857|$857| | |\n",
580
+ "|Other assets|$101| | |$101|\n",
581
+ "|Total|$66,361|$47,910|$12,085|$101|\n",
582
+ "\n",
583
+ "107\n",
584
+ "\n",
585
+ "Meta Platforms, Inc. - Annual Report\n",
586
+ "\n",
587
+ "Table of Contents\n",
588
+ "\n",
589
+ "Fair Value Measurement at Reporting Date Using\n",
590
+ "\n",
591
+ "Description December 31, 2022 Quoted Prices in Active Markets for Identical Assets (Level 1) Significant Other Observable Inputs (Level 2) Significant Unobservable Inputs (Level 3) Cash $6,176 Cash equivalents: Money market funds $8,305 $8,305 Cash equivalents: U.S. government and agency securities $16 $16 Cash equivalents: Time deposits $156 $156 Cash equivalents: Corporate debt securities $28 $28 Total cash and cash equivalents $14,681 $8,321 $184 Marketable securities: U.S. government securities $8,708 $8,708 Marketable securities: U.S. government agency securities $4,989 $4,989 Marketable securities: Corporate debt securities $12,335 $12,335 Marketable securities: Marketable equity securities $25 $25 Total marketable securities $26,057 $13,722 $12,335 Restricted cash equivalents $583 $583 Other assets $157 $157 Total $41,478 $22,626 $12,519 $157\n",
592
+ "\n",
593
+ "Unrealized Losses\n",
594
+ "\n",
595
+ "The following tables summarize our available-for-sale marketable debt securities and cash equivalents with unrealized losses as of December 31, 2023 and 2022, aggregated by major security type and the length of time that individual securities have been in a continuous loss position (in millions):\n",
596
+ "\n",
597
+ "December 31, 2023\n",
598
+ "======== CONTEXT ========\n",
599
+ "included in other assets 866 621 115 Total cash, cash equivalents, and restricted cash $42,827 $15,596 $16,865\n"
600
+ ]
601
+ }
602
+ ]
603
+ },
604
+ {
605
+ "cell_type": "code",
606
+ "source": [
607
+ "# query the rag_chain\n",
608
+ "query2 = \"Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\"\n",
609
+ "response = rag_chain.invoke({\"question\": query2})\n",
610
+ "print(response['response'])"
611
+ ],
612
+ "metadata": {
613
+ "colab": {
614
+ "base_uri": "https://localhost:8080/"
615
+ },
616
+ "outputId": "db77cf3c-0e28-4cce-b0c6-b1103845671d",
617
+ "id": "l5KLh5Nh12aN"
618
+ },
619
+ "execution_count": 89,
620
+ "outputs": [
621
+ {
622
+ "output_type": "stream",
623
+ "name": "stdout",
624
+ "text": [
625
+ "The Directors of Meta Platforms, Inc. listed in the document are:\n",
626
+ "\n",
627
+ "- Mark Zuckerberg\n",
628
+ "- Susan Li\n",
629
+ "- Aaron Anderson\n",
630
+ "- Peggy Alford\n",
631
+ "- Marc L. Andreessen\n",
632
+ "- Andrew W. Houston\n",
633
+ "- Nancy Killefer\n",
634
+ "- Robert M. Kimmitt\n",
635
+ "- Sheryl K. Sandberg\n",
636
+ "- Tracey T. Travis\n",
637
+ "- Tony Xu\n"
638
+ ]
639
+ }
640
+ ]
641
+ },
642
+ {
643
+ "cell_type": "code",
644
+ "source": [
645
+ "for context in response['context']:\n",
646
+ " print('======== CONTEXT ========')\n",
647
+ " print(context.page_content)"
648
+ ],
649
+ "metadata": {
650
+ "colab": {
651
+ "base_uri": "https://localhost:8080/"
652
+ },
653
+ "outputId": "630f0d9f-49e5-4d29-d768-a097e24694f9",
654
+ "id": "yzrKRr3tjpJi"
655
+ },
656
+ "execution_count": 90,
657
+ "outputs": [
658
+ {
659
+ "output_type": "stream",
660
+ "name": "stdout",
661
+ "text": [
662
+ "======== CONTEXT ========\n",
663
+ "10\n",
664
+ "\n",
665
+ "Meta Platforms, Inc. - Annual Report\n",
666
+ "\n",
667
+ "Table of Contents\n",
668
+ "\n",
669
+ "Table of contents content goes here...\n",
670
+ "\n",
671
+ "Signatory Title Date Mark Zuckerberg Chief Executive Officer March 1, 2024 Sheryl Sandberg Chief Operating Officer March 1, 2024 David Wehner Chief Financial Officer March 1, 2024 --- # Meta Platforms, Inc. Annual Report\n",
672
+ "\n",
673
+ "Meta Platforms, Inc. Annual Report\n",
674
+ "\n",
675
+ "Signatures\n",
676
+ "\n",
677
+ "Name Title Date [Signature Name 1] [Title 1] [Date 1] [Signature Name 2] [Title 2] [Date 2] [Signature Name 3] [Title 3] [Date 3] --- # Meta Platforms, Inc. Annual Report\n",
678
+ "\n",
679
+ "Table of Contents\n",
680
+ "\n",
681
+ "Compensation, Benefits, Health, and Well-being\n",
682
+ "\n",
683
+ "We offer competitive compensation to attract and retain the best people, and we help care for our people so they can focus on our mission. Our employees' total compensation package includes market-competitive salary, bonuses or sales incentives, and equity. We generally offer full-time employees equity at the time of hire and through annual equity grants because we want them to be owners of the company and committed to our long-term success. We have conducted pay equity analyses for many years, and continue to be committed to pay equity. For example, in July 2023, we announced that our analyses confirm that we continue to have pay equity across genders globally and by race in the United States for people in similar jobs, accounting for factors such as location, role, and level.\n",
684
+ "\n",
685
+ "Through Life@ Meta, our holistic approach to benefits, we continue to provide our employees and their dependents with resources to help them thrive. We offer a wide range of benefits across areas such as health, family, finance, community, and time away, including family building benefits, family care resources, retirement savings plans, access to legal services, Meta Resource Groups to build community at Meta, and health and well-being benefits.\n",
686
+ "\n",
687
+ "Our health and well-being programs are designed to give employees a choice of flexible benefits to help them reach their personal well-being goals. Our programs are tailored to help boost employee physical and mental health, create financial peace of mind, provide support for families, and help employees build a strong community. Programs are designed and funded to support needs like autism care, cancer care, transgender services, holistic well-being, including mental health programs and retirement savings, which represent a few of the ways we support our employees and their dependents.\n",
688
+ "\n",
689
+ "Diverse and Inclusive Workplace\n",
690
+ "======== CONTEXT ========\n",
691
+ "Meta Platforms, Inc. - List of Subsidiaries\n",
692
+ "\n",
693
+ "List of Subsidiaries - Meta Platforms, Inc.\n",
694
+ "\n",
695
+ "Subsidiary Name Incorporation Cassin Networks ApS (Denmark) Edge Network Services Limited (Ireland) Facebook Circularity, LLC (Delaware) Facebook Holdings, LLC (Delaware) Facebook India Online Services Private Limited (India) Facebook Operations, LLC (Delaware) Facebook Procurement LLC (Delaware) Facebook Serviços Online Do Brasil Ltda. (Brazil) Facebook UK Limited (United Kingdom) FCL Tech Limited (Ireland) Goldframe LLC (Delaware) Greater Kudu LLC (Delaware) Hibiscus Properties, LLC (Delaware) Instagram, LLC (Delaware) Malkoha Pte. Ltd. (Singapore) Meta Payments Inc. (Florida) Meta Platforms Ireland Limited (Ireland) Meta Platforms Technologies, LLC (Delaware) Morning Hornet LLC (Delaware) Pinnacle Sweden AB (Sweden) Raven Northbrook LLC (Delaware) Redale LLC (Delaware) Runways Information Services Limited (Ireland) Scout Development, LLC (Delaware) Siculus, Inc. (Delaware) Sidecat LLC (Delaware) Stadion LLC (Delaware) Starbelt LLC (Delaware) Vitesse, LLC (Delaware) WhatsApp LLC (Delaware) Winner LLC (Delaware) Woolhawk LLC (Delaware) --- ```markdown Firm Name Ernst & Young LLP ------------------ ------------------- Location San Mateo, California Date February 1, 2024 ``` --- Name: Mark Zuckerberg --- --- Title: Board Chair and Chief Executive Officer (Principal Executive Officer) Date: February 1, 2024 --- Date: February 1, 2024 --- --- /s/ SUSAN LI Susan Li Susan Li Chief Financial Officer (Principal Financial Officer) --- Name: Mark Zuckerberg --- --- Title: Board Chair and Chief Executive Officer Date: February 1, 2024 --- Date: February 1, 2024 --- --- /s/ SUSAN LI Susan Li Chief Financial Officer (Principal Financial Officer) --- # Meta Platforms, Inc. - Compensation Recoupment Policy\n",
696
+ "\n",
697
+ "META PLATFORMS, INC. COMPENSATION RECOUPMENT POLICY\n",
698
+ "======== CONTEXT ========\n",
699
+ "Chief Executive Officer\n",
700
+ "Not specified \n",
701
+ "Meta Platforms, Inc. - Annual Report \n",
702
+ "Table of Contents \n",
703
+ "Exhibit Number Exhibit Description Form File No. Exhibit Filing Date Herewith 32.2# Certification of Susan Li, Chief Financial Officer, pursuant to 18 U.S.C. Section 1350, as adopted pursuant to Section 906 of the Sarbanes-Oxley Act of 2002. X 97.1 Compensation Recoupment Policy. X 101.INS Inline XBRL Instance Document (the instance document does not appear in the Interactive Data File because its XBRL tags are embedded within the Inline XBRL document). X 101.SCH Inline XBRL Taxonomy Extension Schema Document. X 101.CAL Inline XBRL Taxonomy Extension Calculation Linkbase Document. X 101.DEF Inline XBRL Taxonomy Extension Definition Linkbase Document. X 101.LAB Inline XBRL Taxonomy Extension Labels Linkbase Document. X 101.PRE Inline XBRL Taxonomy Extension Presentation Linkbase Document. X 104 Cover Page Interactive Data File (formatted as inline XBRL and contained in Exhibit 101). X \n",
704
+ "Indicates a management contract or compensatory plan. \n",
705
+ "This certification is deemed not filed for purposes of Section 18 of the Securities Exchange Act of 1934, as amended (Exchange Act), or otherwise subject to the liability of that section, nor shall it be deemed incorporated by reference into any filing under the Securities Act of 1933, as amended, or the Exchange Act. \n",
706
+ "Item 16. Form 10-K Summary \n",
707
+ "None. \n",
708
+ "130 \n",
709
+ "Meta Platforms, Inc. - Signatures \n",
710
+ "Date Signatory Title February 1, 2024 Susan Li Chief Financial Officer --- # Meta Platforms, Inc. - Signatures \n",
711
+ "Signature\n",
712
+ "Title\n",
713
+ "Date \n",
714
+ "/s/ Mark Zuckerberg\n",
715
+ "Board Chair and Chief Executive Officer\n",
716
+ "February 1, 2024 \n",
717
+ "/s/ Susan Li\n",
718
+ "Chief Financial Officer\n",
719
+ "February 1, 2024 \n",
720
+ "/S/ Aaron Anderson\n",
721
+ "Chief Accounting Officer\n",
722
+ "February 1, 2024 \n",
723
+ "/s/ Peggy Alford\n",
724
+ "Director\n",
725
+ "February 1, 2024 \n",
726
+ "/s/ Marc L. Andreessen\n",
727
+ "Director\n",
728
+ "February 1, 2024 \n",
729
+ "/s/ Andrew W. Houston\n",
730
+ "Director\n",
731
+ "February 1, 2024 \n",
732
+ "/s/ Nancy Killefer\n",
733
+ "Director\n",
734
+ "February 1, 2024 \n",
735
+ "/s/ Robert M. Kimmitt\n",
736
+ "Director\n",
737
+ "February 1, 2024 \n",
738
+ "/s/ Sheryl K. Sandberg\n",
739
+ "Director\n",
740
+ "February 1, 2024 \n",
741
+ "/s/ Tracey T. Travis\n",
742
+ "Director\n",
743
+ "February 1, 2024 \n",
744
+ "/s/ Tony Xu\n",
745
+ "Director\n",
746
+ "February 1, 2024 \n",
747
+ "Meta Platforms, Inc. - Description of Capital Stock \n",
748
+ "DESCRIPTION OF CAPITAL STOCK \n",
749
+ "The following description of capital stock of Meta Platforms, Inc. (the “company,” “we,” “us” and “our”) summarizes certain provisions of our amended\n",
750
+ "======== CONTEXT ========\n",
751
+ "Signatures \n",
752
+ "Name Title Date [Signature] Mark Zuckerberg Chief Executive Officer [Signature] David M. Wehner Chief Financial Officer --- # Meta Platforms, Inc. - List of Subsidiaries \n",
753
+ "List of Subsidiaries - Meta Platforms, Inc. \n",
754
+ "Subsidiary Name\n",
755
+ "Incorporation \n",
756
+ "Cassin Networks ApS (Denmark) \n",
757
+ "Edge Network Services Limited (Ireland) \n",
758
+ "Facebook Circularity, LLC (Delaware) \n",
759
+ "Facebook Holdings, LLC (Delaware) \n",
760
+ "Facebook India Online Services Private Limited (India) \n",
761
+ "Facebook Operations, LLC (Delaware) \n",
762
+ "Facebook Procurement LLC (Delaware) \n",
763
+ "Facebook Serviços Online Do Brasil Ltda. (Brazil) \n",
764
+ "Facebook UK Limited (United Kingdom) \n",
765
+ "FCL Tech Limited (Ireland) \n",
766
+ "Goldframe LLC (Delaware) \n",
767
+ "Greater Kudu LLC (Delaware) \n",
768
+ "Hibiscus Properties, LLC (Delaware) \n",
769
+ "Instagram, LLC (Delaware) \n",
770
+ "Malkoha Pte. Ltd. (Singapore) \n",
771
+ "Meta Payments Inc. (Florida) \n",
772
+ "Meta Platforms Ireland Limited (Ireland) \n",
773
+ "Meta Platforms Technologies, LLC (Delaware) \n",
774
+ "Morning Hornet LLC (Delaware) \n",
775
+ "Pinnacle Sweden AB (Sweden) \n",
776
+ "Raven Northbrook LLC (Delaware) \n",
777
+ "Redale LLC (Delaware) \n",
778
+ "Runways Information Services Limited (Ireland) \n",
779
+ "Scout Development, LLC (Delaware) \n",
780
+ "Siculus, Inc. (Delaware) \n",
781
+ "Sidecat LLC (Delaware) \n",
782
+ "Stadion LLC (Delaware) \n",
783
+ "Starbelt LLC (Delaware) \n",
784
+ "Vitesse, LLC (Delaware) \n",
785
+ "WhatsApp LLC (Delaware) \n",
786
+ "Winner LLC (Delaware) \n",
787
+ "Woolhawk LLC (Delaware) \n",
788
+ "Meta Platforms, Inc. - Consent of Independent Registered Public Accounting Firm \n",
789
+ "Registration Statement\n",
790
+ "Description \n",
791
+ "Form S-8 No. 333-270184\n",
792
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
793
+ "Form S-8 No. 333-262508\n",
794
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
795
+ "Form S-8 No. 333-252518\n",
796
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
797
+ "Form S-8 No. 333-236161\n",
798
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
799
+ "Form S-8 No. 333-229457\n",
800
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
801
+ "Form S-8 No. 333-222823\n",
802
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
803
+ "Form S-8 No. 333-186402\n",
804
+ "2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
805
+ "Form S-8 No. 333-181566\n",
806
+ "2005 Officers’ Stock Plan, 2005 Stock Plan, and 2012 Equity Incentive Plan of Meta Platforms, Inc. \n",
807
+ "Form S-3 No. 333-271535\n",
808
+ "Meta Platforms, Inc. \n",
809
+ "Consent of Ernst & Young LLP, San Mateo, California, dated February 1, 2024, regarding the consolidated financial statements and internal control over financial reporting of Meta Platforms, Inc. for the year ended December 31, 2023. \n",
810
+ "Meta Platforms, Inc. - Annual Report\n"
811
+ ]
812
+ }
813
+ ]
814
+ },
815
+ {
816
+ "cell_type": "code",
817
+ "source": [],
818
+ "metadata": {
819
+ "id": "Pog6YfXRqs84"
820
+ },
821
+ "execution_count": null,
822
+ "outputs": []
823
+ },
824
+ {
825
+ "cell_type": "code",
826
+ "source": [
827
+ "# query the rag_chain\n",
828
+ "response = rag_chain.invoke({\"question\": \"What's the par value of Meta's Class A common stock?\"})\n",
829
+ "print(response['response'])"
830
+ ],
831
+ "metadata": {
832
+ "colab": {
833
+ "base_uri": "https://localhost:8080/"
834
+ },
835
+ "outputId": "b64b17fb-c707-4628-e907-04a8425285fc",
836
+ "id": "QEUGDMqnOBYL"
837
+ },
838
+ "execution_count": 91,
839
+ "outputs": [
840
+ {
841
+ "output_type": "stream",
842
+ "name": "stdout",
843
+ "text": [
844
+ "The par value of Meta's Class A common stock is $0.000006 per share.\n"
845
+ ]
846
+ }
847
+ ]
848
+ },
849
+ {
850
+ "cell_type": "code",
851
+ "source": [
852
+ "# query the rag_chain\n",
853
+ "response = rag_chain.invoke({\"question\": \"What is Meta's dividend policy?\"})\n",
854
+ "print(response['response'])"
855
+ ],
856
+ "metadata": {
857
+ "colab": {
858
+ "base_uri": "https://localhost:8080/"
859
+ },
860
+ "outputId": "1d19b246-5a07-49c4-ede7-11fe92e335ab",
861
+ "id": "2pIq--IfOToh"
862
+ },
863
+ "execution_count": 95,
864
+ "outputs": [
865
+ {
866
+ "output_type": "stream",
867
+ "name": "stdout",
868
+ "text": [
869
+ "Meta's dividend policy states that prior to 2024, the company had never declared or paid any cash dividend on their common stock. However, on February 1, 2024, they announced the initiation of their first ever cash dividend program. This program includes a cash dividend of $0.50 per share of Class A common stock and Class B common stock, equivalent to $2.00 per share on an annual basis. The first cash dividend was scheduled to be paid on March 26, 2024 to all holders of record of common stock at the close of business on February 22, 2024. The payment of future cash dividends is subject to future declaration by their board of directors, based on various factors including capital availability, market conditions, laws, and the best interests of stockholders.\n"
870
+ ]
871
+ }
872
+ ]
873
+ },
874
+ {
875
+ "cell_type": "code",
876
+ "source": [
877
+ "# query the rag_chain\n",
878
+ "response = rag_chain.invoke({\"question\": \"What is Meta's current net worth?\"})\n",
879
+ "print(response['response'])"
880
+ ],
881
+ "metadata": {
882
+ "colab": {
883
+ "base_uri": "https://localhost:8080/"
884
+ },
885
+ "outputId": "62ddea20-e2e7-4fab-b4f0-d147dbad18f7",
886
+ "id": "3BhBr0GdO8KW"
887
+ },
888
+ "execution_count": 96,
889
+ "outputs": [
890
+ {
891
+ "output_type": "stream",
892
+ "name": "stdout",
893
+ "text": [
894
+ "Meta's current net worth, based on the information provided in the annual report, is $229,623 million as of December 31, 2023.\n"
895
+ ]
896
+ }
897
+ ]
898
+ },
899
+ {
900
+ "cell_type": "code",
901
+ "source": [],
902
+ "metadata": {
903
+ "id": "B_s-Pep5OOnS"
904
+ },
905
+ "execution_count": null,
906
+ "outputs": []
907
+ }
908
+ ]
909
+ }
notebooks/Meta_10K_RAG_Strategies.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ aiohttp==3.9.5
3
+ aiosignal==1.3.1
4
+ annotated-types==0.6.0
5
+ anyio==3.7.1
6
+ async-timeout==4.0.3
7
+ asyncer==0.0.2
8
+ attrs==23.2.0
9
+ backoff==2.2.1
10
+ beautifulsoup4==4.12.3
11
+ bidict==0.23.1
12
+ certifi==2024.2.2
13
+ chainlit==1.0.506
14
+ chardet==5.2.0
15
+ charset-normalizer==3.3.2
16
+ chevron==0.14.0
17
+ click==8.1.7
18
+ dataclasses-json==0.5.14
19
+ dataclasses-json-speakeasy==0.5.11
20
+ deepdiff==7.0.1
21
+ Deprecated==1.2.14
22
+ dirtyjson==1.0.8
23
+ distro==1.9.0
24
+ emoji==2.11.1
25
+ fastapi==0.110.3
26
+ fastapi-socketio==0.0.10
27
+ filetype==1.2.0
28
+ frozenlist==1.4.1
29
+ fsspec==2024.3.1
30
+ googleapis-common-protos==1.63.0
31
+ greenlet==3.0.3
32
+ grpcio==1.63.0
33
+ grpcio-tools==1.62.2
34
+ h11==0.14.0
35
+ h2==4.1.0
36
+ hpack==4.0.0
37
+ httpcore==1.0.5
38
+ httpx==0.27.0
39
+ hyperframe==6.0.1
40
+ idna==3.7
41
+ importlib-metadata==7.0.0
42
+ joblib==1.4.2
43
+ jsonpatch==1.33
44
+ jsonpath-python==1.0.6
45
+ jsonpointer==2.4
46
+ langchain==0.1.17
47
+ langchain-community==0.0.36
48
+ langchain-core==0.1.49
49
+ langchain-openai==0.1.5
50
+ langchain-text-splitters==0.0.1
51
+ langdetect==1.0.9
52
+ langsmith==0.1.53
53
+ Lazify==0.4.0
54
+ literalai==0.0.509
55
+ llama-index==0.10.33
56
+ llama-index-agent-openai==0.2.3
57
+ llama-index-cli==0.1.12
58
+ llama-index-core==0.10.33
59
+ llama-index-embeddings-openai==0.1.9
60
+ llama-index-indices-managed-llama-cloud==0.1.6
61
+ llama-index-legacy==0.9.48
62
+ llama-index-llms-openai==0.1.16
63
+ llama-index-multi-modal-llms-openai==0.1.5
64
+ llama-index-program-openai==0.1.6
65
+ llama-index-question-gen-openai==0.1.3
66
+ llama-index-readers-file==0.1.20
67
+ llama-index-readers-llama-parse==0.1.4
68
+ llama-parse==0.4.2
69
+ llamaindex-py-client==0.1.19
70
+ lxml==5.2.1
71
+ Markdown==3.6
72
+ marshmallow==3.21.2
73
+ multidict==6.0.5
74
+ mypy-extensions==1.0.0
75
+ networkx==3.3
76
+ nltk==3.8.1
77
+ numpy==1.26.4
78
+ openai==1.25.1
79
+ opentelemetry-api==1.24.0
80
+ opentelemetry-exporter-otlp==1.24.0
81
+ opentelemetry-exporter-otlp-proto-common==1.24.0
82
+ opentelemetry-exporter-otlp-proto-grpc==1.24.0
83
+ opentelemetry-exporter-otlp-proto-http==1.24.0
84
+ opentelemetry-instrumentation==0.45b0
85
+ opentelemetry-proto==1.24.0
86
+ opentelemetry-sdk==1.24.0
87
+ opentelemetry-semantic-conventions==0.45b0
88
+ ordered-set==4.1.0
89
+ orjson==3.10.2
90
+ pandas==2.2.2
91
+ pillow==10.3.0
92
+ portalocker==2.8.2
93
+ protobuf==4.25.3
94
+ pydantic==2.7.1
95
+ pydantic_core==2.18.2
96
+ PyJWT==2.8.0
97
+ pypdf==4.2.0
98
+ python-dotenv==1.0.1
99
+ python-engineio==4.9.0
100
+ python-graphql-client==0.4.3
101
+ python-iso639==2024.4.27
102
+ python-magic==0.4.27
103
+ python-multipart==0.0.9
104
+ python-socketio==5.11.2
105
+ pytz==2024.1
106
+ PyYAML==6.0.1
107
+ qdrant-client==1.9.0
108
+ rapidfuzz==3.8.1
109
+ regex==2024.4.28
110
+ requests==2.31.0
111
+ simple-websocket==1.0.0
112
+ sniffio==1.3.1
113
+ soupsieve==2.5
114
+ SQLAlchemy==2.0.29
115
+ starlette==0.37.2
116
+ striprtf==0.0.26
117
+ syncer==2.0.3
118
+ tabulate==0.9.0
119
+ tenacity==8.2.3
120
+ tiktoken==0.6.0
121
+ tomli==2.0.1
122
+ tqdm==4.66.3
123
+ typing-inspect==0.9.0
124
+ tzdata==2024.1
125
+ unstructured==0.13.6
126
+ unstructured-client==0.18.0
127
+ uptrace==1.24.0
128
+ urllib3==2.2.1
129
+ uvicorn==0.25.0
130
+ watchfiles==0.20.0
131
+ websockets==12.0
132
+ wrapt==1.16.0
133
+ wsproto==1.2.0
134
+ yarl==1.9.4
135
+ zipp==3.18.1