DSPy
DSPy is a fantastic framework for LLMs that introduces an automatic compiler that teaches LMs how to conduct the declarative steps in your program. Specifically, the DSPy compiler will internally trace your program and then craft high-quality prompts for large LMs (or train automatic finetunes for small LMs) to teach them the steps of your task.
Thanks to Omar Khattab we have an integration! It works with any LCEL chains with some minor modifications.
This short tutorial demonstrates how this proof-of-concept feature works. This will not give you the full power of DSPy or LangChain yet, but we will expand it if there's high demand.
Note: this was slightly modified from the original example Omar wrote for DSPy. If you are interested in LangChain <> DSPy but coming from the DSPy side, I'd recommend checking that out. You can find that here.
Let's take a look at an example. In this example we will make a simple RAG pipeline. We will use DSPy to "compile" our program and learn an optimized prompt.
This example uses the ColBERTv2
model.
See the ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction paper.
Install dependencies
!pip install -U dspy-ai !pip install -U openai jinja2 !pip install -U langchain langchain-community langchain-openai langchain-core