Skip to content

Commit 2d505e1

Browse files
authored
Add warning for ComponentDevice (#495)
1 parent 0ae9d95 commit 2d505e1

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎tutorials/33_Hybrid_Retrieval.ipynb‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
"metadata": {
66
"id": "kTas9ZQ7lXP7"
77
},
8-
"source": "# Tutorial: Creating a Hybrid Retrieval Pipeline\n\n- **Level**: Intermediate\n- **Time to complete**: 15 minutes\n- **Components Used**: [`DocumentSplitter`](https://docs.haystack.deepset.ai/docs/documentsplitter), [`SentenceTransformersDocumentEmbedder`](https://docs.haystack.deepset.ai/docs/sentencetransformersdocumentembedder), [`InMemoryDocumentStore`](https://docs.haystack.deepset.ai/docs/inmemorydocumentstore), [`InMemoryBM25Retriever`](https://docs.haystack.deepset.ai/docs/inmemorybm25retriever), [`InMemoryEmbeddingRetriever`](https://docs.haystack.deepset.ai/docs/inmemoryembeddingretriever), and [`SentenceTransformersSimilarityRanker`](https://docs.haystack.deepset.ai/docs/sentencetransformerssimilarityranker)\n- **Prerequisites**: None\n- **Goal**: After completing this tutorial, you will have learned about creating a hybrid retrieval and when it's useful."
8+
"source": [
9+
"# Tutorial: Creating a Hybrid Retrieval Pipeline\n",
10+
"\n",
11+
"- **Level**: Intermediate\n",
12+
"- **Time to complete**: 15 minutes\n",
13+
"- **Components Used**: [`DocumentSplitter`](https://docs.haystack.deepset.ai/docs/documentsplitter), [`SentenceTransformersDocumentEmbedder`](https://docs.haystack.deepset.ai/docs/sentencetransformersdocumentembedder), [`InMemoryDocumentStore`](https://docs.haystack.deepset.ai/docs/inmemorydocumentstore), [`InMemoryBM25Retriever`](https://docs.haystack.deepset.ai/docs/inmemorybm25retriever), [`InMemoryEmbeddingRetriever`](https://docs.haystack.deepset.ai/docs/inmemoryembeddingretriever), and [`SentenceTransformersSimilarityRanker`](https://docs.haystack.deepset.ai/docs/sentencetransformerssimilarityranker)\n",
14+
"- **Prerequisites**: None\n",
15+
"- **Goal**: After completing this tutorial, you will have learned about creating a hybrid retrieval and when it's useful."
16+
]
917
},
1018
{
1119
"cell_type": "markdown",
@@ -38,7 +46,13 @@
3846
"id": "L40ZxZW8lXQh"
3947
},
4048
"outputs": [],
41-
"source": "%%bash\n\npip install haystack-ai\npip install \"datasets>=2.6.1\"\npip install sentence-transformers-haystack"
49+
"source": [
50+
"%%bash\n",
51+
"\n",
52+
"pip install haystack-ai\n",
53+
"pip install \"datasets>=2.6.1\"\n",
54+
"pip install sentence-transformers-haystack"
55+
]
4256
},
4357
{
4458
"cell_type": "markdown",
@@ -144,7 +158,7 @@
144158
"\n",
145159
"document_splitter = DocumentSplitter(split_by=\"word\", split_length=512, split_overlap=32)\n",
146160
"document_embedder = SentenceTransformersDocumentEmbedder(\n",
147-
" model=\"BAAI/bge-small-en-v1.5\", device=ComponentDevice.from_str(\"cuda:0\")\n",
161+
" model=\"BAAI/bge-small-en-v1.5\", device=ComponentDevice.from_str(\"cuda:0\") # remove the device argument if you are not using a GPU\n",
148162
")\n",
149163
"document_writer = DocumentWriter(document_store)\n",
150164
"\n",
@@ -194,7 +208,7 @@
194208
},
195209
{
196210
"cell_type": "code",
197-
"execution_count": 7,
211+
"execution_count": null,
198212
"metadata": {
199213
"id": "DVfQvnWYrMWr"
200214
},
@@ -204,7 +218,7 @@
204218
"from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersTextEmbedder\n",
205219
"\n",
206220
"text_embedder = SentenceTransformersTextEmbedder(\n",
207-
" model=\"BAAI/bge-small-en-v1.5\", device=ComponentDevice.from_str(\"cuda:0\")\n",
221+
" model=\"BAAI/bge-small-en-v1.5\", device=ComponentDevice.from_str(\"cuda:0\") # remove the device argument if you are not using a GPU\n",
208222
")\n",
209223
"embedding_retriever = InMemoryEmbeddingRetriever(document_store)\n",
210224
"bm25_retriever = InMemoryBM25Retriever(document_store)"
@@ -215,7 +229,11 @@
215229
"metadata": {
216230
"id": "r8_jHzmosbC_"
217231
},
218-
"source": "### 2) Rank the Results\n\nUse the [SentenceTransformersSimilarityRanker](https://docs.haystack.deepset.ai/docs/sentencetransformerssimilarityranker) that scores the relevancy of all retrieved documents for the given search query by using a cross encoder model. In this example, you will use [BAAI/bge-reranker-base](https://huggingface.co/BAAI/bge-reranker-base) model to rank the retrieved documents but you can replace this model with other cross-encoder models on Hugging Face."
232+
"source": [
233+
"### 2) Rank the Results\n",
234+
"\n",
235+
"Use the [SentenceTransformersSimilarityRanker](https://docs.haystack.deepset.ai/docs/sentencetransformerssimilarityranker) that scores the relevancy of all retrieved documents for the given search query by using a cross encoder model. In this example, you will use [BAAI/bge-reranker-base](https://huggingface.co/BAAI/bge-reranker-base) model to rank the retrieved documents but you can replace this model with other cross-encoder models on Hugging Face."
236+
]
219237
},
220238
{
221239
"cell_type": "code",
@@ -224,7 +242,11 @@
224242
"id": "cN0woIxHs4Ng"
225243
},
226244
"outputs": [],
227-
"source": "from haystack_integrations.components.rankers.sentence_transformers import SentenceTransformersSimilarityRanker\n\nranker = SentenceTransformersSimilarityRanker(model=\"BAAI/bge-reranker-base\")"
245+
"source": [
246+
"from haystack_integrations.components.rankers.sentence_transformers import SentenceTransformersSimilarityRanker\n",
247+
"\n",
248+
"ranker = SentenceTransformersSimilarityRanker(model=\"BAAI/bge-reranker-base\")"
249+
]
228250
},
229251
{
230252
"cell_type": "markdown",

‎tutorials/39_Embedding_Metadata_for_Improved_Retrieval.ipynb‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
"execution_count": null,
5252
"metadata": {},
5353
"outputs": [],
54-
"source": "%%bash\n\npip install haystack-ai wikipedia sentence-transformers-haystack"
54+
"source": [
55+
"%%bash\n",
56+
"\n",
57+
"pip install haystack-ai wikipedia sentence-transformers-haystack"
58+
]
5559
},
5660
{
5761
"cell_type": "markdown",
@@ -83,7 +87,7 @@
8387
},
8488
{
8589
"cell_type": "code",
86-
"execution_count": 16,
90+
"execution_count": null,
8791
"metadata": {},
8892
"outputs": [],
8993
"source": [
@@ -92,8 +96,6 @@
9296
"from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersDocumentEmbedder\n",
9397
"from haystack.components.writers import DocumentWriter\n",
9498
"from haystack.document_stores.types import DuplicatePolicy\n",
95-
"from haystack.utils import ComponentDevice\n",
96-
"\n",
9799
"\n",
98100
"def create_indexing_pipeline(document_store, metadata_fields_to_embed=None):\n",
99101
" document_cleaner = DocumentCleaner()\n",

0 commit comments

Comments
 (0)