/ docs-website / versioned_docs / version-2.18 / pipeline-components / embedders / stackittextembedder.mdx
stackittextembedder.mdx
1 --- 2 title: "STACKITTextEmbedder" 3 id: stackittextembedder 4 slug: "/stackittextembedder" 5 description: "This component enables text embedding using the STACKIT API." 6 --- 7 8 # STACKITTextEmbedder 9 10 This component enables text embedding using the STACKIT API. 11 12 | | | 13 | -------------------------------------- | ----------------------------------------------------------------------------------------- | 14 | **Most common position in a pipeline** | Before an embedding [Retriever](../retrievers.mdx) in a query/RAG pipeline | 15 | **Mandatory init variables** | "model": The model used through the STACKIT API | 16 | **Mandatory run variables** | “text”: A string | 17 | **Output variables** | “embedding”: A list of float numbers | 18 | **API reference** | [STACKIT](/reference/integrations-stackit) | 19 | **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/stackit | 20 21 ## Overview 22 23 `STACKITTextEmbedder` enables text embedding models served by STACKIT through their API. 24 25 ### Parameters 26 27 To use the `STACKITTextEmbedder`, ensure you have set a `STACKIT_API_KEY` as an environment variable. Alternatively, provide the API key as an environment variable with a different name or a token by setting `api_key` and using Haystack’s [secret management](../../concepts/secret-management.mdx). 28 29 Set your preferred supported model with the `model` parameter when initializing the component. See the full list of all supported models on the [STACKIT website](https://docs.stackit.cloud/stackit/en/models-licenses-319914532.html). 30 31 Optionally, you can change the default `api_base_url`, which is `"https://api.openai-compat.model-serving.eu01.onstackit.cloud/v1"`. 32 33 You can pass any text generation parameters valid for the STACKIT Chat Completion API directly to this component with the `generation_kwargs` parameter in the init or run methods. 34 35 The component needs a text input to operate. 36 37 ## Usage 38 39 Install the `stackit-haystack` package to use the `STACKITTextEmbedder` and set an environment variable called `STACKIT_API_KEY` to your API key. 40 41 ```shell 42 pip install stackit-haystack 43 ``` 44 45 ### On its own 46 47 ```python 48 from haystack_integrations.components.embedders.stackit import STACKITTextEmbedder 49 50 text_embedder = STACKITTextEmbedder(model="intfloat/e5-mistral-7b-instruct") 51 52 print(text_embedder.run("I love pizza!")) 53 54 ## {'embedding': [0.0215301513671875, 0.01499176025390625, ...]} 55 ``` 56 57 ### In a pipeline 58 59 You can also use `STACKITTextEmbedder` in your pipeline. 60 61 ```python 62 from haystack import Document 63 from haystack import Pipeline 64 from haystack.document_stores.in_memory import InMemoryDocumentStore 65 from haystack_integrations.components.embedders.stackit import ( 66 STACKITTextEmbedder, 67 STACKITDocumentEmbedder, 68 ) 69 from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever 70 71 document_store = InMemoryDocumentStore() 72 73 documents = [ 74 Document(content="My name is Wolfgang and I live in Berlin"), 75 Document(content="I saw a black horse running"), 76 Document(content="Germany has many big cities"), 77 ] 78 79 document_embedder = STACKITDocumentEmbedder(model="intfloat/e5-mistral-7b-instruct") 80 documents_with_embeddings = document_embedder.run(documents)["documents"] 81 document_store.write_documents(documents_with_embeddings) 82 83 text_embedder = STACKITTextEmbedder(model="intfloat/e5-mistral-7b-instruct") 84 85 query_pipeline = Pipeline() 86 query_pipeline.add_component("text_embedder", text_embedder) 87 query_pipeline.add_component( 88 "retriever", 89 InMemoryEmbeddingRetriever(document_store=document_store), 90 ) 91 query_pipeline.connect("text_embedder.embedding", "retriever.query_embedding") 92 93 query = "Where does Wolfgang live?" 94 95 result = query_pipeline.run({"text_embedder": {"text": query}}) 96 97 print(result["retriever"]["documents"][0]) 98 99 ## Document(id=..., content: 'My name is Wolfgang and I live in Berlin', score: ...) 100 ``` 101 102 You can find more usage examples in the STACKIT integration [repository](https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/stackit/examples) and its [integration page](https://haystack.deepset.ai/integrations/stackit).