Build a RAG (retrieval-augmented generation) pipeline with Chains
Help for setting up a clean development environment
>=3.8,<3.13
. To set up a fresh development environment,
you can use the following commands, creating a environment named chains_env
using pyenv
:.bashrc
:
rag.py
in a new directory with:
VectorStore
, a Chainlet that implements a vector database with a retrieval
function.LLMClient
, a Stub for connecting to a deployed LLM.RAG
, the entrypoint Chainlet that orchestrates the RAG pipeline and
has VectorStore
and LLMClient
as dependencies.chromadb
to stand in for a more complex system.
The Chainlet has three parts:
remote_config
, which
configures a Docker image on deployment with dependencies.__init__()
, which runs once when the Chainlet is spun up, and creates the
vector database with ten sample bios.run_remote()
, which runs
each time the Chainlet is called and is the sole public interface for the
Chainlet.run_remote()
, but as a call
to the deployed model.
For our LLM, we’ll use Phi-3 Mini Instruct, a small-but-mighty open source LLM.
__init__
function in this Chainlet takes two new arguments:
chains.depends()
. Only
Chainlets, not Stubs, need to be added in this fashion.chains.depends_context()
to inject a context object at runtime. This context object is required to
initialize the LLMClient
stub.LLM_URL
.BASETEN_API_KEY
.