Skip to main content

DSPy-Clarifai Integration

Learn how to use DSPy along with Clarifai Python SDK


DSPy is a framework designed to address the fragility issue encountered in language model based applications by emphasizing programming over prompting. It will optimize the entire pipeline for your specific task.

This approach eliminates the need for repetitive manual adjustments to prompts whenever a component is modified. By integrating Clarifai into DSPy, users gain access to Clarifai's capabilities, particularly its ability to call language models (LLM) from the Clarifai platform.

This integration empowers users to utilize Clarifai's application as a retriever for their vector search use cases. Clarifai, as a platform, offers a suite of tools making it a valuable addition to DSPy. Its integration allows for the seamless incorporation of LLM models into the DSPy framework, enhancing the efficiency and effectiveness of tasks such as vector search.

Why integrating with Clarifai is beneficial?

  • Access to Advanced Features: Clarifai provides advanced capabilities that can be leveraged within DSPy to enhance various tasks.
  • Improved Retrieval for Vector Search: By utilizing Clarifai as a retriever for vector search use cases, users can benefit from its robust search capabilities, potentially improving the accuracy and speed of search operations.
  • Reduced Manual Adjustments: Since DSPy emphasizes programming over prompting, the integration with Clarifai helps minimize the need for repetitive manual adjustments to prompts, thereby enhancing overall efficiency and reducing the risk of errors.


0:02 - Intro to DSPy

1:09 - DSPy Concepts

2:27 - Why Clarifai Integration is useful

2:51 - Code Demo

3:04 - Create Clarifai PAT

3:25 - Get Clarifai User ID

3:42 - Create an App on the Clarifai Platform

4:43 - Choose LLM from Clarifai

6:20 - Create Clarifai Vector Store

6:40 - Initialize LLM

6:55 - Create Clarifai Retriever

7:25 - First Example Run

8:50 - Using dspy.Retrieve method

9:50 - Building a RAG Module

11:09 - Creating Custom Signature Class

12:11 - Final Output