diff --git a/docs/docs/deep-dive/retrieval_models_clients/ClarifaiRM.md b/docs/docs/deep-dive/retrieval_models_clients/ClarifaiRM.md index 108f1ab2b..528b97d23 100644 --- a/docs/docs/deep-dive/retrieval_models_clients/ClarifaiRM.md +++ b/docs/docs/deep-dive/retrieval_models_clients/ClarifaiRM.md @@ -2,7 +2,6 @@ [Clarifai](https://clarifai.com/) is a powerful AI platform that provides vector search capabilities through its search API. DSPy has integrated ClarifaiRM to support efficient text search and retrieval through its specialized indexing and ability to handle large-scale document collections. - To support passage retrieval, ClarifaiRM assumes that documents have been properly ingested into a Clarifai application with the following: - Text data properly indexed and stored - Appropriate search configurations set up in the Clarifai platform @@ -14,22 +13,18 @@ The ClarifaiRM module requires the `clarifai` Python package. If not already ins pip install clarifai ``` -**Note:** - - Before using ClarifaiRM, ensure you have: - 1. Created a Clarifai account and application - 2. Ingested your documents into the application - 3. Obtained your User ID, App ID, and Personal Access Token (PAT) +**Note:** Before using ClarifaiRM, ensure you have: +1. Created a Clarifai account and application +2. Ingested your documents into the application +3. Obtained your User ID, App ID, and Personal Access Token (PAT) ## Setting up the ClarifaiRM Client -The constructor initializes an instance of the `ClarifaiRM` class, which requires authentication credentials and configuration to connect to your Clarifai application. The constructor initializes an instance of the `ClarifaiRM` class, which requires authentication credentials and configuration to connect to your Clarifai application. - `clarifai_user_id` (_str_): Your unique Clarifai user identifier. - `clarifai_app_id` (_str_): The ID of your Clarifai application where documents are stored. - `clarifai_pat` (_Optional[str]_): Your Clarifai Personal Access Token (PAT). It will look for `CLARIFAI_PAT` in environment variables if not provided. -- `clarifai_pat` (_Optional[str]_): Your Clarifai Personal Access Token (PAT). It will look for `CLARIFAI_PAT` in environment variables if not provided. - `k` (_int_, _optional_): The number of top passages to retrieve. Defaults to 3. Example of the ClarifaiRM constructor: @@ -43,10 +38,7 @@ ClarifaiRM( ) ``` -**Note:** - - - The PAT can be provided either directly to the constructor or through the `CLARIFAI_PAT` environment variable. For security best practices, using environment variables is recommended. +**Note:** The PAT can be provided either directly to the constructor or through the `CLARIFAI_PAT` environment variable. For security best practices, using environment variables is recommended. ## Under the Hood @@ -80,27 +72,22 @@ import os from dspy.retrieve.clarifai_rm import ClarifaiRM import dspy - os.environ["CLARIFAI_PAT"] = "your_pat_key" - retriever_model = ClarifaiRM( clarifai_user_id="your_user_id", clarifai_app_id="your_app_id", k=5 ) - turbo = dspy.OpenAI(model="gpt-3.5-turbo") dspy.settings.configure(lm=turbo, rm=retriever_model) - results = retriever_model("Explore the significance of quantum computing") ``` ### Multiple Queries ```python - queries = [ "What is machine learning?", "How does deep learning work?", @@ -114,10 +101,8 @@ results = retriever_model(queries, k=3) ```python from dspy import Retrieve - retrieve = Retrieve(k=5) - class RAG(dspy.Module): def __init__(self): super().__init__() @@ -127,14 +112,12 @@ class RAG(dspy.Module): passages = self.retrieve(query) return passages - rag = RAG() result = rag("What are the latest developments in AI?") ``` ### Handling Results ```python - results = retriever_model("quantum computing advances", k=5) for i, result in enumerate(results, 1): @@ -144,7 +127,6 @@ for i, result in enumerate(results, 1): first_passage = results[0].long_text - num_results = len(results) ``` @@ -164,7 +146,6 @@ class QAChain(dspy.Module): answer = self.generate_answer(question=question, context=context) return answer - qa = QAChain() answer = qa("What are the main applications of quantum computing?") ``` @@ -182,12 +163,8 @@ except Exception as e: print(f"Error occurred: {e}") ``` - -**Note:** - - These examples assume you have: - - A properly configured Clarifai application - - Valid authentication credentials - - Documents already ingested into your Clarifai app - - The necessary environment variables set up - +**Note:** These examples assume you have: +- A properly configured Clarifai application +- Valid authentication credentials +- Documents already ingested into your Clarifai app +- The necessary environment variables set up \ No newline at end of file