Skip to content

Commit 8d3436a

Browse files
committed
Adding VoyageAI EmbeddingEncoder description to embedding.mdx
1 parent 7f0e105 commit 8d3436a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

open-source/core-functionality/embedding.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,47 @@ print(query_embedding, query)
179179
print(embedding_encoder.is_unit_vector(), embedding_encoder.num_of_dimensions())
180180

181181
```
182+
183+
184+
## `VertexAIEmbeddingEncoder`
185+
186+
The `VoyageAIEmbeddingEncoder` class connects to the VoyageAI to obtain embeddings for pieces of text.
187+
188+
`embed_documents` will receive a list of Elements, and return an updated list which includes the `embeddings` attribute for each Element.
189+
190+
`embed_query` will receive a query as a string, and return a list of floats which is the embedding vector for the given query string.
191+
192+
`num_of_dimensions` is a metadata property that denotes the number of dimensions in any embedding vector obtained via this class.
193+
194+
`is_unit_vector` is a metadata property that denotes if embedding vectors obtained via this class are unit vectors.
195+
196+
The following code block shows an example of how to use `VoyageAIEmbeddingEncoder`. You will see the updated elements list (with the `embeddings` attribute included for each element), the embedding vector for the query string, and some metadata properties about the embedding model.
197+
198+
To use Voyage AI you will need to pass Voyage AI API Key (obtained from [https://dash.voyageai.com/](https://dash.voyageai.com/)) as the `api_key` parameter.
199+
200+
The `model_name` parameter is mandatory, please check the available models at [https://docs.voyageai.com/docs/embeddings](https://docs.voyageai.com/docs/embeddings)
201+
202+
```python
203+
import os
204+
205+
from unstructured.documents.elements import Text
206+
from unstructured.embed.voyageai import VoyageAIEmbeddingConfig, VoyageAIEmbeddingEncoder
207+
208+
embedding_encoder = VoyageAIEmbeddingEncoder(
209+
config=VoyageAIEmbeddingConfig(
210+
api_key=os.environ["VOYAGE_API_KEY"],
211+
model_name="voyage-law-2"
212+
)
213+
)
214+
elements = embedding_encoder.embed_documents(
215+
elements=[Text("This is sentence 1"), Text("This is sentence 2")],
216+
)
217+
218+
query = "This is the query"
219+
query_embedding = embedding_encoder.embed_query(query=query)
220+
221+
[print(e, e.embeddings) for e in elements]
222+
print(query, query_embedding)
223+
print(embedding_encoder.is_unit_vector, embedding_encoder.num_of_dimensions)
224+
225+
```

0 commit comments

Comments
 (0)