You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/api/retrieval_model_clients/AzureCognitiveSearch.md
+7-2
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
7
7
### Constructor
8
8
9
-
The constructor initializes an instance of the `AzureCognitiveSearch` class and sets up parameters for sending queries and retreiving results with the Azure Cognitive Search server.
9
+
The constructor initializes an instance of the `AzureCognitiveSearch` class and sets up parameters for sending queries and retreiving results with the Azure Cognitive Search server.
10
10
11
11
```python
12
12
classAzureCognitiveSearch:
@@ -21,6 +21,7 @@ class AzureCognitiveSearch:
21
21
```
22
22
23
23
**Parameters:**
24
+
24
25
-`search_service_name` (_str_): Name of Azure Cognitive Search server.
25
26
-`search_api_key` (_str_): API Authentication token for accessing Azure Cognitive Search server.
26
27
-`search_index_name` (_str_): Name of search index in the Azure Cognitive Search server.
@@ -31,4 +32,8 @@ class AzureCognitiveSearch:
31
32
32
33
Refer to [ColBERTv2](/api/retrieval_model_clients/ColBERTv2) documentation. Keep in mind there is no `simplify` flag for AzureCognitiveSearch.
33
34
34
-
AzureCognitiveSearch supports sending queries and processing the received results, mapping content and scores to a correct format for the Azure Cognitive Search server.
35
+
AzureCognitiveSearch supports sending queries and processing the received results, mapping content and scores to a correct format for the Azure Cognitive Search server.
36
+
37
+
### Deprecation Notice
38
+
39
+
This module is scheduled for removal in future releases. Please use the AzureAISearchRM class from dspy.retrieve.azureaisearch_rm instead.For more information, refer to the updated documentation(docs/docs/deep-dive/retrieval_models_clients/Azure.mdx).
Copy file name to clipboardexpand all lines: docs/api/retrieval_model_clients/ChromadbRM.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ Search the chromadb collection for the top `k` passages matching the given query
41
41
ChromadbRM have the flexibility from a variety of embedding functions as outlined in the [chromadb embeddings documentation](https://docs.trychroma.com/embeddings). While different options are available, this example demonstrates how to utilize OpenAI embeddings specifically.
42
42
43
43
```python
44
-
from dspy.retrieve.chroma_rmimport ChromadbRM
44
+
from dspy.retrieve.chromadb_rmimport ChromadbRM
45
45
import os
46
46
import openai
47
47
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
@@ -62,4 +62,4 @@ results = retriever_model("Explore the significance of quantum computing", k=5)
@@ -31,11 +27,16 @@ You can simply call the LM with a string to give it a raw prompt, i.e. a string.
31
27
gpt3_turbo("hello! this is a raw prompt to GPT-3.5")
32
28
```
33
29
30
+
**Output:**
31
+
```text
32
+
['Hello! How can I assist you today?']
33
+
```
34
+
34
35
This is almost never the recommended way to interact with LMs in DSPy, but it is allowed.
35
36
36
37
## Using the LM with DSPy signatures.
37
38
38
-
You can also use the LM via DSPy [signatures] and [modules], which we discuss in more depth in the remaining guides.
39
+
You can also use the LM via DSPy [`signature` (input/output spec)](https://dspy-docs.vercel.app/docs/building-blocks/signatures) and [`modules`](https://dspy-docs.vercel.app/docs/building-blocks/modules), which we discuss in more depth in the remaining guides.
39
40
40
41
```python
41
42
# Define a module (ChainOfThought) and assign it a signature (return an answer, given a question).
@@ -172,4 +173,4 @@ model = 'dist/prebuilt/mlc-chat-Llama-2-7b-chat-hf-q4f16_1'
Copy file name to clipboardexpand all lines: docs/docs/building-blocks/2-signatures.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ sidebar_position: 2
6
6
7
7
When we assign tasks to LMs in DSPy, we specify the behavior we need as a Signature.
8
8
9
-
**A signature is a declarative specification of input/output behavior of a DSPy module.** Signatures allow you tell the LM _what_ it needs to do, rather than specify _how_ we should ask the LM to do it.
9
+
**A signature is a declarative specification of input/output behavior of a DSPy module.** Signatures allow you to tell the LM _what_ it needs to do, rather than specify _how_ we should ask the LM to do it.
10
10
11
11
12
12
You're probably familiar with function signatures, which specify the input and output arguments and their types. DSPy signatures are similar, but the differences are that:
@@ -157,4 +157,4 @@ Prediction(
157
157
158
158
While signatures are convenient for prototyping with structured inputs/outputs, that's not the main reason to use them!
159
159
160
-
You should compose multiple signatures into bigger [DSPy modules] and [compile] these modules into optimized prompts and finetunes.
160
+
You should compose multiple signatures into bigger [DSPy modules](https://dspy-docs.vercel.app/docs/building-blocks/modules) and [compile these modules into optimized prompts](https://dspy-docs.vercel.app/docs/building-blocks/optimizers#what-does-a-dspy-optimizer-tune-how-does-it-tune-them) and finetunes.
Copy file name to clipboardexpand all lines: docs/docs/building-blocks/solving_your_task.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Using DSPy well for solving a new task is just doing good machine learning with
8
8
9
9
What this means is that it's an iterative process. You make some initial choices, which will be sub-optimal, and then you refine them incrementally.
10
10
11
-
As we discuss below, you will define your task and the metrics you want to maximize, and prepare a few example inputs — typically without labels (or only with labels for the final outputs, if your metric requires them). Then, you build your pipeline by selecting built-in layers [(`modules`)](https://dspy-docs.vercel.app/docs/building-blocks/modules) to use, giving each layer a [`signature` (input/output spec)](https://dspy-docs.vercel.app/docs/building-blocks/signatures), and then calling your modules freely in your Python code. Lastly, you use a DSPy [`optimizer`]https://dspy-docs.vercel.app/docs/building-blocks/optimizers) to compile your code into high-quality instructions, automatic few-shot examples, or updated LM weights for your LM.
11
+
As we discuss below, you will define your task and the metrics you want to maximize, and prepare a few example inputs — typically without labels (or only with labels for the final outputs, if your metric requires them). Then, you build your pipeline by selecting built-in layers [(`modules`)](https://dspy-docs.vercel.app/docs/building-blocks/modules) to use, giving each layer a [`signature` (input/output spec)](https://dspy-docs.vercel.app/docs/building-blocks/signatures), and then calling your modules freely in your Python code. Lastly, you use a DSPy [`optimizer`](https://dspy-docs.vercel.app/docs/building-blocks/optimizers) to compile your code into high-quality instructions, automatic few-shot examples, or updated LM weights for your LM.
A retrieval module that utilizes Azure AI Search to retrieve top passages for a given query.
8
10
9
11
## Prerequisites
10
12
11
13
```bash
12
-
pip install azure-core
14
+
pip install azure-search-documents
13
15
```
14
16
15
-
## Setting up the Azure Client
16
-
17
-
The constructor initializes an instance of the `AzureCognitiveSearch` class and sets up parameters for sending queries and retrieving results with the Azure Cognitive Search server.
18
-
19
-
-`search_service_name` (_str_): Name of Azure Cognitive Search server.
20
-
-`search_api_key` (_str_): API Authentication token for accessing Azure Cognitive Search server.
21
-
-`search_index_name` (_str_): Name of search index in the Azure Cognitive Search server.
22
-
-`field_text` (_str_): Field name that maps to DSP "content" field.
23
-
-`field_score` (_str_): Field name that maps to DSP "score" field.
17
+
## Setting up the AzureAISearchRM Client
18
+
19
+
The constructor initializes an instance of the `AzureAISearchRM` class and sets up parameters for sending queries and retrieving results with the Azure AI Search server.
20
+
21
+
-`search_service_name` (str): The name of the Azure AI Search service.
22
+
-`search_api_key` (str): The API key for accessing the Azure AI Search service.
23
+
-`search_index_name` (str): The name of the search index in the Azure AI Search service.
24
+
-`field_text` (str): The name of the field containing text content in the search index. This field will be mapped to the "content" field in the dsp framework.
25
+
-`k` (int, optional): The default number of top passages to retrieve. Defaults to 3.
26
+
-`semantic_ranker` (bool, optional): Whether to use semantic ranking. Defaults to False.
27
+
-`filter` (str, optional): Additional filter query. Defaults to None.
28
+
-`query_language` (str, optional): The language of the query. Defaults to "en-Us".
29
+
-`query_speller` (str, optional): The speller mode. Defaults to "lexicon".
30
+
-`use_semantic_captions` (bool, optional): Whether to use semantic captions. Defaults to False.
31
+
-`query_type` (Optional[QueryType], optional): The type of query. Defaults to QueryType.FULL.
32
+
-`semantic_configuration_name` (str, optional): The name of the semantic configuration. Defaults to None.
33
+
34
+
Available Query Types:
35
+
36
+
SIMPLE
37
+
"""Uses the simple query syntax for searches. Search text is interpreted using a simple query
38
+
#: language that allows for symbols such as +, * and "". Queries are evaluated across all
39
+
#: searchable fields by default, unless the searchFields parameter is specified."""
40
+
FULL
41
+
"""Uses the full Lucene query syntax for searches. Search text is interpreted using the Lucene
42
+
#: query language which allows field-specific and weighted searches, as well as other advanced
43
+
#: features."""
44
+
SEMANTIC
45
+
"""Best suited for queries expressed in natural language as opposed to keywords. Improves
46
+
#: precision of search results by re-ranking the top search results using a ranking model trained
47
+
#: on the Web corpus.""
48
+
49
+
More Details: https://learn.microsoft.com/en-us/azure/search/search-query-overview
50
+
51
+
Example of the AzureAISearchRM constructor:
24
52
25
53
```python
26
-
classAzureCognitiveSearch:
27
-
def__init__(
28
-
self,
29
-
search_service_name: str,
30
-
search_api_key: str,
31
-
search_index_name: str,
32
-
field_text: str,
33
-
field_score: str, # required field to map with "score" field in dsp framework
-`query` (_str_): Search query string used for retrieval sent to Azure Cognitive Search service.
43
-
-`k` (_int_, _optional_): Number of passages to retrieve. Defaults to 10.
75
+
76
+
-`query_or_queries` (Union[str, List[str]]): The query or queries to search for.
77
+
-`k` (_Optional[int]_, _optional_): The number of results to retrieve. If not specified, defaults to the value set during initialization.
44
78
45
79
**Returns:**
46
-
-`Union[list[str], list[dotdict]]`: list of top-k search results
47
80
48
-
Internally, the method handles the specifics of preparing the request query to the Azure Cognitive Search service and corresponding payload to obtain the response.
81
+
-`dspy.Prediction`: Contains the retrieved passages, each represented as a `dotdict` with a `long_text` attribute.
49
82
50
-
The method sends a query and number of desired passages (k) to Azure Cognitive Search using `azure_search_request`. This function communicates with Azure and processes the search results as a list of dictionaries.
83
+
Internally, the method handles the specifics of preparing the request query to the Azure AI Search service and corresponding payload to obtain the response.
51
84
52
-
This is then converted to `dotdict` objects that internally map the retrieved content and scores, listed by descending order of relevance.
85
+
The function handles the retrieval of the top-k passages based on the provided query.
53
86
54
-
## Sending Retrieval Requests via Azure Client
55
-
1)_**Recommended**_ Configure default RM using `dspy.configure`.
87
+
## Sending Retrieval Requests via AzureAISearchRM Client
88
+
89
+
1._**Recommended**_ Configure default RM using `dspy.configure`.
56
90
57
91
This allows you to define programs in DSPy and have DSPy internally conduct retrieval using `dsp.retrieve` on the query on the configured RM.
58
92
59
93
```python
60
94
import dspy
61
-
import dsp
95
+
from dspy.retrieve.azureaisearch_rm import AzureAISearchRM
96
+
97
+
azure_search = AzureAISearchRM(
98
+
"search_service_name",
99
+
"search_api_key",
100
+
"search_index_name",
101
+
"field_text",
102
+
"k"=3
103
+
)
62
104
63
-
dspy.settings.configure(rm=TODO)
64
-
retrieval_response = dsp.retrieve("When was the first FIFA World Cup held?", k=5)
105
+
dspy.settings.configure(rm=azure_search)
106
+
retrieve = dspy.Retrieve(k=3)
107
+
retrieval_response = retrieve("What is Thermodynamics").passages
65
108
66
109
for result in retrieval_response:
67
110
print("Text:", result, "\n")
68
111
```
69
112
113
+
2. Generate responses using the client directly.
70
114
71
-
2) Generate responses using the client directly.
72
115
```python
73
-
import dspy
116
+
from dspy.retrieve.azureaisearch_rm import AzureAISearchRM
74
117
75
-
retrieval_response = TODO('When was the first FIFA World Cup held?', k=5)
118
+
azure_search = AzureAISearchRM(
119
+
"search_service_name",
120
+
"search_api_key",
121
+
"search_index_name",
122
+
"field_text",
123
+
"k"=3
124
+
)
76
125
126
+
retrieval_response = azure_search("What is Thermodynamics", k=3)
0 commit comments