Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

updated README and notebook

zilto56684509137f
diff --git a/examples/rag-lancedb-ingestion/README.md b/examples/rag-lancedb-ingestion/README.md
index bf59f768..312e4d43 100644
--- a/examples/rag-lancedb-ingestion/README.md
+++ b/examples/rag-lancedb-ingestion/README.md
@@ -6,7 +6,9 @@ This example shows how to build a chatbot with RAG over Substack blogs (or any R
> Burr UI brings a new level of observability to your RAG application via OpenTelemetry
-Burr + [LanceDB](https://lancedb.github.io/lancedb/) constitute a powerful, but lightweight combo to build retrieval-augmented generative (RAG) agents. LanceDB makes it easy to swap embedding provider, and hides this concerns from the Burr application layer. For this example, we'll be using [OpenAI](https://github.com/openai/openai-python) for embedding and response generation.
+Burr + [LanceDB](https://lancedb.github.io/lancedb/) constitute a powerful, but lightweight combo to build retrieval-augmented generative (RAG) agents. Burr allows to define complex agents in an easy-to-understand and debug manner. It also provides all the right features to help you productionize agents including: monitoring, storing interactions, streaming, and a powerful open-source UI.
+
+LanceDB makes it easy to swap embedding provider, and hides this concerns from the Burr application layer. For this example, we'll be using [OpenAI](https://github.com/openai/openai-python) for embedding and response generation.
By leveraging the [Burr integration with OpenTelemetry](https://blog.dagworks.io/p/building-generative-ai-agent-based), we get full visibility into the OpenAI API requests/responses and the LanceDB operations for free.
diff --git a/examples/rag-lancedb-ingestion/__init__.py b/examples/rag-lancedb-ingestion/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/examples/rag-lancedb-ingestion/application.py b/examples/rag-lancedb-ingestion/application.py
index 53517ef8..2b693000 100644
--- a/examples/rag-lancedb-ingestion/application.py
+++ b/examples/rag-lancedb-ingestion/application.py
@@ -9,7 +9,7 @@ from burr.lifecycle import PostRunStepHook
@action(reads=[], writes=["relevant_chunks", "chat_history"])
-def retrieve_relevant_chunks(
+def relevant_chunk_retrieval(
state: State,
user_query: str,
lancedb_con: lancedb.DBConnection,
@@ -68,14 +68,14 @@ def build_application() -> Application:
return (
ApplicationBuilder()
.with_actions(
- retrieve_relevant_chunks.bind(lancedb_con=lancedb_con),
+ relevant_chunk_retrieval.bind(lancedb_con=lancedb_con),
bot_turn.bind(llm_client=llm_client),
)
.with_transitions(
- ("retrieve_relevant_chunks", "bot_turn"),
- ("bot_turn", "retrieve_relevant_chunks"),
+ ("relevant_chunk_retrieval", "bot_turn"),
+ ("bot_turn", "relevant_chunk_retrieval"),
)
- .with_entrypoint("retrieve_relevant_chunks")
+ .with_entrypoint("relevant_chunk_retrieval")
.with_tracker("local", project="substack-rag", use_otel_tracing=True)
.with_hooks(PrintBotAnswer())
.build()
diff --git a/examples/rag-lancedb-ingestion/notebook.ipynb b/examples/rag-lancedb-ingestion/notebook.ipynb
index b0fa86a7..8032eed7 100644
--- a/examples/rag-lancedb-ingestion/notebook.ipynb
+++ b/examples/rag-lancedb-ingestion/notebook.ipynb
@@ -10,11 +10,11 @@
"\n",
"The stack includes:\n",
"\n",
- "- Burr\n",
- "- LanceDB\n",
- "- dlt\n",
- "- OpenAI\n",
- "- OpenTelemetry"
+ "- Burr: define your RAG logic \n",
+ "- LanceDB: store and retrieve documents using vector search\n",
+ "- dlt: ingest unstructured web pages and store them as structured documents\n",
+ "- OpenAI: embed documents for vector search and generate answers using LLMs\n",
+ "- OpenTelemetry: automatically track telemetry from Burr, LanceDB, and OpenAI in a unified way"
]
},
{
@@ -191,7 +191,7 @@
"import os\n",
"\n",
"# set your OpenAI API key\n",
- "openai_api_key = \n",
+ "openai_api_key = ...\n",
"\n",
"# this environment variable isn't needed by dlt, but we'll use it later\n",
"os.environ[\"OPENAI_API_KEY\"] = openai_api_key\n",
@@ -212,18 +212,9 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/home/tjean/projects/dagworks/burr/examples/rag-lancedb-ingestion/.venv/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
- " from .autonotebook import tqdm as notebook_tqdm\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"from dlt.destinations.adapters import lancedb_adapter\n",
"import dlt.destinations.impl.lancedb.models\n",
@@ -266,10 +257,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Pipeline substack-blog load step completed in 5.06 seconds\n",
+ "Pipeline substack-blog load step completed in 3.02 seconds\n",
"1 load package(s) were loaded to destination LanceDB and into dataset dagworks\n",
- "The LanceDB destination used <dlt.destinations.impl.lancedb.configuration.LanceDBCredentials object at 0x7f2626a4ead0> location to store data\n",
- "Load package 1724874594.4636345 is LOADED and contains no failed jobs\n"
+ "The LanceDB destination used <dlt.destinations.impl.lancedb.configuration.LanceDBCredentials object at 0x7fbe84da5810> location to store data\n",
+ "Load package 1724941288.3716326 is LOADED and contains no failed jobs\n"
]
}
],
@@ -297,7 +288,7 @@
"First, we define actions the agent can take with the `@action` decorator. The function must take a `State` object as first argument and return a `State` object. The decorator specifies which `State` fields can be read from and written to.\n",
"\n",
"The next cell contains two actions:\n",
- "- `retrieve_relevant_chunks()` reads from the LanceDB table `dagworks___contexts` that was generated by `dlt` and retrieves the top 4 most similar rows to the `user_query` string. It writes the search results to the `relevant_chunks` state field and appends the user input to the `chat_history` state field.\n",
+ "- `relevant_chunk_retrieval()` reads from the LanceDB table `dagworks___contexts` that was generated by `dlt` and retrieves the top 4 most similar rows to the `user_query` string. It writes the search results to the `relevant_chunks` state field and appends the user input to the `chat_history` state field.\n",
"- `bot_turn()` reads the `chat_history` and the `relevant_chunks` from state, combine the text into a prompt and send a request to OpenAI. The LLM's response is appended to the `chat_history` state field."
]
},
@@ -316,7 +307,7 @@
"\n",
"\n",
"@action(reads=[], writes=[\"relevant_chunks\", \"chat_history\"])\n",
- "def retrieve_relevant_chunks(\n",
+ "def relevant_chunk_retrieval(\n",
" state: State,\n",
" user_query: str,\n",
" lancedb_con: lancedb.DBConnection,\n",
@@ -377,7 +368,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -389,58 +380,58 @@
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
- "<svg width=\"419pt\" height=\"177pt\"\n",
- " viewBox=\"0.00 0.00 418.50 177.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ "<svg width=\"417pt\" height=\"177pt\"\n",
+ " viewBox=\"0.00 0.00 416.50 177.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 173)\">\n",
"<title>%3</title>\n",
- "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-173 414.5,-173 414.5,4 -4,4\"/>\n",
- "<!-- retrieve_relevant_chunks -->\n",
+ "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-173 412.5,-173 412.5,4 -4,4\"/>\n",
+ "<!-- relevant_chunk_retrieval -->\n",
"<g id=\"node1\" class=\"node\">\n",
- "<title>retrieve_relevant_chunks</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M335.5,-103C335.5,-103 163.5,-103 163.5,-103 157.5,-103 151.5,-97 151.5,-91 151.5,-91 151.5,-78 151.5,-78 151.5,-72 157.5,-66 163.5,-66 163.5,-66 335.5,-66 335.5,-66 341.5,-66 347.5,-72 347.5,-78 347.5,-78 347.5,-91 347.5,-91 347.5,-97 341.5,-103 335.5,-103\"/>\n",
- "<text text-anchor=\"middle\" x=\"249.5\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">retrieve_relevant_chunks</text>\n",
+ "<title>relevant_chunk_retrieval</title>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M331.5,-103C331.5,-103 163.5,-103 163.5,-103 157.5,-103 151.5,-97 151.5,-91 151.5,-91 151.5,-78 151.5,-78 151.5,-72 157.5,-66 163.5,-66 163.5,-66 331.5,-66 331.5,-66 337.5,-66 343.5,-72 343.5,-78 343.5,-78 343.5,-91 343.5,-91 343.5,-97 337.5,-103 331.5,-103\"/>\n",
+ "<text text-anchor=\"middle\" x=\"247.5\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">relevant_chunk_retrieval</text>\n",
"</g>\n",
"<!-- bot_turn -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>bot_turn</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M277.5,-37C277.5,-37 221.5,-37 221.5,-37 215.5,-37 209.5,-31 209.5,-25 209.5,-25 209.5,-12 209.5,-12 209.5,-6 215.5,0 221.5,0 221.5,0 277.5,0 277.5,0 283.5,0 289.5,-6 289.5,-12 289.5,-12 289.5,-25 289.5,-25 289.5,-31 283.5,-37 277.5,-37\"/>\n",
- "<text text-anchor=\"middle\" x=\"249.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">bot_turn</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M275.5,-37C275.5,-37 219.5,-37 219.5,-37 213.5,-37 207.5,-31 207.5,-25 207.5,-25 207.5,-12 207.5,-12 207.5,-6 213.5,0 219.5,0 219.5,0 275.5,0 275.5,0 281.5,0 287.5,-6 287.5,-12 287.5,-12 287.5,-25 287.5,-25 287.5,-31 281.5,-37 275.5,-37\"/>\n",
+ "<text text-anchor=\"middle\" x=\"247.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">bot_turn</text>\n",
"</g>\n",
- "<!-- retrieve_relevant_chunks&#45;&gt;bot_turn -->\n",
+ "<!-- relevant_chunk_retrieval&#45;&gt;bot_turn -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
- "<title>retrieve_relevant_chunks&#45;&gt;bot_turn</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M243.38,-65.67C242.84,-59.99 242.65,-53.55 242.8,-47.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"246.3,-47.42 243.39,-37.23 239.31,-47.01 246.3,-47.42\"/>\n",
+ "<title>relevant_chunk_retrieval&#45;&gt;bot_turn</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M241.38,-65.67C240.84,-59.99 240.65,-53.55 240.8,-47.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"244.3,-47.42 241.39,-37.23 237.31,-47.01 244.3,-47.42\"/>\n",
"</g>\n",
"<!-- input__user_query -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__user_query</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"238.5,-169 92.5,-169 92.5,-132 238.5,-132 238.5,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"165.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: user_query</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"236.5,-169 90.5,-169 90.5,-132 236.5,-132 236.5,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"163.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: user_query</text>\n",
"</g>\n",
- "<!-- input__user_query&#45;&gt;retrieve_relevant_chunks -->\n",
+ "<!-- input__user_query&#45;&gt;relevant_chunk_retrieval -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
- "<title>input__user_query&#45;&gt;retrieve_relevant_chunks</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M188.9,-131.67C198.08,-124.68 208.74,-116.56 218.54,-109.09\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"220.68,-111.86 226.52,-103.01 216.44,-106.29 220.68,-111.86\"/>\n",
+ "<title>input__user_query&#45;&gt;relevant_chunk_retrieval</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M186.9,-131.67C196.08,-124.68 206.74,-116.56 216.54,-109.09\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"218.68,-111.86 224.52,-103.01 214.44,-106.29 218.68,-111.86\"/>\n",
"</g>\n",
"<!-- input__lancedb_con -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>input__lancedb_con</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"410.5,-169 256.5,-169 256.5,-132 410.5,-132 410.5,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"333.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: lancedb_con</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"408.5,-169 254.5,-169 254.5,-132 408.5,-132 408.5,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"331.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: lancedb_con</text>\n",
"</g>\n",
- "<!-- input__lancedb_con&#45;&gt;retrieve_relevant_chunks -->\n",
+ "<!-- input__lancedb_con&#45;&gt;relevant_chunk_retrieval -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
- "<title>input__lancedb_con&#45;&gt;retrieve_relevant_chunks</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M310.1,-131.67C300.92,-124.68 290.26,-116.56 280.46,-109.09\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"282.56,-106.29 272.48,-103.01 278.32,-111.86 282.56,-106.29\"/>\n",
+ "<title>input__lancedb_con&#45;&gt;relevant_chunk_retrieval</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M308.1,-131.67C298.92,-124.68 288.26,-116.56 278.46,-109.09\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"280.56,-106.29 270.48,-103.01 276.32,-111.86 280.56,-106.29\"/>\n",
"</g>\n",
- "<!-- bot_turn&#45;&gt;retrieve_relevant_chunks -->\n",
+ "<!-- bot_turn&#45;&gt;relevant_chunk_retrieval -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
- "<title>bot_turn&#45;&gt;retrieve_relevant_chunks</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M255.61,-37.23C256.16,-42.91 256.35,-49.34 256.2,-55.57\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"252.7,-55.49 255.62,-65.67 259.69,-55.89 252.7,-55.49\"/>\n",
+ "<title>bot_turn&#45;&gt;relevant_chunk_retrieval</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M253.61,-37.23C254.16,-42.91 254.35,-49.34 254.2,-55.57\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"250.7,-55.49 253.62,-65.67 257.69,-55.89 250.7,-55.49\"/>\n",
"</g>\n",
"<!-- input__llm_client -->\n",
"<g id=\"node5\" class=\"node\">\n",
@@ -451,17 +442,17 @@
"<!-- input__llm_client&#45;&gt;bot_turn -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>input__llm_client&#45;&gt;bot_turn</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M116.99,-65.84C142.79,-56.82 174.07,-45.88 199.76,-36.9\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"201.02,-40.16 209.31,-33.56 198.71,-33.55 201.02,-40.16\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M116.44,-65.84C141.86,-56.85 172.67,-45.96 198.03,-36.99\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"199.19,-40.29 207.45,-33.66 196.86,-33.69 199.19,-40.29\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
- "<graphviz.graphs.Digraph at 0x7f2626e03c50>"
+ "<graphviz.graphs.Digraph at 0x7fbe85a88ed0>"
]
},
- "execution_count": 9,
+ "execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -471,12 +462,12 @@
"\n",
"application = (\n",
" ApplicationBuilder()\n",
- " .with_actions(retrieve_relevant_chunks, bot_turn)\n",
+ " .with_actions(relevant_chunk_retrieval, bot_turn)\n",
" .with_transitions(\n",
- " (\"retrieve_relevant_chunks\", \"bot_turn\"),\n",
- " (\"bot_turn\", \"retrieve_relevant_chunks\"),\n",
+ " (\"relevant_chunk_retrieval\", \"bot_turn\"),\n",
+ " (\"bot_turn\", \"relevant_chunk_retrieval\"),\n",
" )\n",
- " .with_entrypoint(\"retrieve_relevant_chunks\")\n",
+ " .with_entrypoint(\"relevant_chunk_retrieval\")\n",
" .build()\n",
")\n",
"application.visualize()"
@@ -497,7 +488,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -521,7 +512,7 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 12,
"metadata": {},
"outputs": [
{
@@ -533,55 +524,55 @@
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
- "<svg width=\"204pt\" height=\"177pt\"\n",
- " viewBox=\"0.00 0.00 204.00 177.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ "<svg width=\"200pt\" height=\"177pt\"\n",
+ " viewBox=\"0.00 0.00 200.00 177.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 173)\">\n",
"<title>%3</title>\n",
- "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-173 200,-173 200,4 -4,4\"/>\n",
- "<!-- retrieve_relevant_chunks -->\n",
+ "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-173 196,-173 196,4 -4,4\"/>\n",
+ "<!-- relevant_chunk_retrieval -->\n",
"<g id=\"node1\" class=\"node\">\n",
- "<title>retrieve_relevant_chunks</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M184,-103C184,-103 12,-103 12,-103 6,-103 0,-97 0,-91 0,-91 0,-78 0,-78 0,-72 6,-66 12,-66 12,-66 184,-66 184,-66 190,-66 196,-72 196,-78 196,-78 196,-91 196,-91 196,-97 190,-103 184,-103\"/>\n",
- "<text text-anchor=\"middle\" x=\"98\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">retrieve_relevant_chunks</text>\n",
+ "<title>relevant_chunk_retrieval</title>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M180,-103C180,-103 12,-103 12,-103 6,-103 0,-97 0,-91 0,-91 0,-78 0,-78 0,-72 6,-66 12,-66 12,-66 180,-66 180,-66 186,-66 192,-72 192,-78 192,-78 192,-91 192,-91 192,-97 186,-103 180,-103\"/>\n",
+ "<text text-anchor=\"middle\" x=\"96\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">relevant_chunk_retrieval</text>\n",
"</g>\n",
"<!-- bot_turn -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>bot_turn</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M126,-37C126,-37 70,-37 70,-37 64,-37 58,-31 58,-25 58,-25 58,-12 58,-12 58,-6 64,0 70,0 70,0 126,0 126,0 132,0 138,-6 138,-12 138,-12 138,-25 138,-25 138,-31 132,-37 126,-37\"/>\n",
- "<text text-anchor=\"middle\" x=\"98\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">bot_turn</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M124,-37C124,-37 68,-37 68,-37 62,-37 56,-31 56,-25 56,-25 56,-12 56,-12 56,-6 62,0 68,0 68,0 124,0 124,0 130,0 136,-6 136,-12 136,-12 136,-25 136,-25 136,-31 130,-37 124,-37\"/>\n",
+ "<text text-anchor=\"middle\" x=\"96\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">bot_turn</text>\n",
"</g>\n",
- "<!-- retrieve_relevant_chunks&#45;&gt;bot_turn -->\n",
+ "<!-- relevant_chunk_retrieval&#45;&gt;bot_turn -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
- "<title>retrieve_relevant_chunks&#45;&gt;bot_turn</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M91.88,-65.67C91.34,-59.99 91.15,-53.55 91.3,-47.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"94.8,-47.42 91.89,-37.23 87.81,-47.01 94.8,-47.42\"/>\n",
+ "<title>relevant_chunk_retrieval&#45;&gt;bot_turn</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M89.88,-65.67C89.34,-59.99 89.15,-53.55 89.3,-47.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"92.8,-47.42 89.89,-37.23 85.81,-47.01 92.8,-47.42\"/>\n",
"</g>\n",
"<!-- input__user_query -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__user_query</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"171,-169 25,-169 25,-132 171,-132 171,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"98\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: user_query</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"169,-169 23,-169 23,-132 169,-132 169,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"96\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: user_query</text>\n",
"</g>\n",
- "<!-- input__user_query&#45;&gt;retrieve_relevant_chunks -->\n",
+ "<!-- input__user_query&#45;&gt;relevant_chunk_retrieval -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
- "<title>input__user_query&#45;&gt;retrieve_relevant_chunks</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M98,-131.67C98,-125.99 98,-119.55 98,-113.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"101.5,-113.23 98,-103.23 94.5,-113.23 101.5,-113.23\"/>\n",
+ "<title>input__user_query&#45;&gt;relevant_chunk_retrieval</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M96,-131.67C96,-125.99 96,-119.55 96,-113.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"99.5,-113.23 96,-103.23 92.5,-113.23 99.5,-113.23\"/>\n",
"</g>\n",
- "<!-- bot_turn&#45;&gt;retrieve_relevant_chunks -->\n",
+ "<!-- bot_turn&#45;&gt;relevant_chunk_retrieval -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
- "<title>bot_turn&#45;&gt;retrieve_relevant_chunks</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M104.11,-37.23C104.66,-42.91 104.85,-49.34 104.7,-55.57\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"101.2,-55.49 104.12,-65.67 108.19,-55.89 101.2,-55.49\"/>\n",
+ "<title>bot_turn&#45;&gt;relevant_chunk_retrieval</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M102.11,-37.23C102.66,-42.91 102.85,-49.34 102.7,-55.57\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"99.2,-55.49 102.12,-65.67 106.19,-55.89 99.2,-55.49\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
- "<graphviz.graphs.Digraph at 0x7f2626bae550>"
+ "<graphviz.graphs.Digraph at 0x7fbecfcbe5d0>"
]
},
- "execution_count": 11,
+ "execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
@@ -600,14 +591,14 @@
"application = (\n",
" ApplicationBuilder()\n",
" .with_actions(\n",
- " retrieve_relevant_chunks.bind(lancedb_con=lancedb_con),\n",
+ " relevant_chunk_retrieval.bind(lancedb_con=lancedb_con),\n",
" bot_turn.bind(llm_client=llm_client),\n",
" )\n",
" .with_transitions(\n",
- " (\"retrieve_relevant_chunks\", \"bot_turn\"),\n",
- " (\"bot_turn\", \"retrieve_relevant_chunks\"),\n",
+ " (\"relevant_chunk_retrieval\", \"bot_turn\"),\n",
+ " (\"bot_turn\", \"relevant_chunk_retrieval\"),\n",
" )\n",
- " .with_entrypoint(\"retrieve_relevant_chunks\")\n",
+ " .with_entrypoint(\"relevant_chunk_retrieval\")\n",
" .with_tracker(\"local\", project=\"substack-rag\", use_otel_tracing=True)\n",
" .with_hooks(PrintBotAnswer())\n",
" .build()\n",
@@ -625,9 +616,34 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "## Lauching RAG application ##\n",
+ "\n",
+ "🤖: Burr can be incredibly helpful if you're developing applications that require state management and debugging capabilities. Here are a few ways it can assist you:\n",
+ "\n",
+ "1. **State-Driven Logic**: Burr allows you to structure your application around actions that depend on the state, giving you fine control over the flow of your application. This is particularly useful for complex applications where the next step depends on the current state.\n",
+ "\n",
+ "2. **Easy Debugging**: With Burr, you can gain visibility into the decisions your application makes. If something goes wrong, you can rewind to a previous state and inspect what happened leading up to the issue. This makes identifying bugs much easier.\n",
+ "\n",
+ "3. **Forking Applications**: The ability to fork your application from any point in time allows you to create different branches of your application state, which can be useful for testing alternate paths or scenarios.\n",
+ "\n",
+ "4. **Integration with Other Frameworks**: Burr is designed to complement other frameworks, such as Hamilton. This makes it versatile and allows you to integrate it into your existing projects seamlessly.\n",
+ "\n",
+ "5. **User Input Handling**: You can define how your application interacts with user inputs, enabling the creation of interactive applications that respond dynamically to user actions.\n",
+ "\n",
+ "6. **Simplified Action Declarations**: By defining actions as functions or objects, you can keep your code organized and easy to follow. This can lead to more maintainable code, especially in large projects.\n",
+ "\n",
+ "If you're working on applications that require robust state management, dynamic responses, and efficient debugging, Burr could be a fantastic addition to your toolkit. Is there a specific type of application you have in mind that you'd like to develop with Burr?\n"
+ ]
+ }
+ ],
"source": [
"# Launch the Burr application in a `while` loop\n",
"print(\"\\n## Lauching RAG application ##\")\n",
@@ -649,7 +665,15 @@
"metadata": {},
"source": [
"# 3. Explore Burr UI\n",
- "After using the `Application`, use the command `burr` to launch the Burr UI and investigate the tracked execution!\n",
+ "After using the `Application`, use the command `burr` to launch the Burr UI.\n",
+ "\n",
+ "Burr UI allows you to:\n",
+ "- explore past executions and current ones in real-time\n",
+ "- see the application move through states\n",
+ "- view code code failures\n",
+ "- inspect tracked attributes (LLM prompts and responses, vector database calls, token counts)\n",
+ "- one-click to create test fixtures from specific states\n",
+ "- and more!\n",
"\n",
"![](burr-ui.gif)"
]
diff --git a/examples/rag-lancedb-ingestion/utils.py b/examples/rag-lancedb-ingestion/utils.py
index 30ec927e..ece96683 100644
--- a/examples/rag-lancedb-ingestion/utils.py
+++ b/examples/rag-lancedb-ingestion/utils.py
@@ -28,10 +28,7 @@ def instrument():
def _compact_hash(digest: bytes) -> str:
- """Compact the hash to a string that's safe to pass around.
- NOTE this is particularly relevant for th Hamilton UI and
- passing hashes/fingerprints through web services.
- """
+ """Compact the hash to a string that's safe to pass around."""
return base64.urlsafe_b64encode(digest).decode()