Skip to content

Commit 7b2a591

Browse files
authored
Adding VoyageAI EmbeddingEncoder description to embedding.mdx (#43)
1 parent 12a8966 commit 7b2a591

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
@@ -201,3 +201,47 @@ print(query_embedding, query)
201201
print(embedding_encoder.is_unit_vector(), embedding_encoder.num_of_dimensions())
202202

203203
```
204+
205+
206+
## `VertexAIEmbeddingEncoder`
207+
208+
The `VoyageAIEmbeddingEncoder` class connects to the VoyageAI to obtain embeddings for pieces of text.
209+
210+
`embed_documents` will receive a list of Elements, and return an updated list which includes the `embeddings` attribute for each Element.
211+
212+
`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.
213+
214+
`num_of_dimensions` is a metadata property that denotes the number of dimensions in any embedding vector obtained via this class.
215+
216+
`is_unit_vector` is a metadata property that denotes if embedding vectors obtained via this class are unit vectors.
217+
218+
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.
219+
220+
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.
221+
222+
The `model_name` parameter is mandatory, please check the available models at [https://docs.voyageai.com/docs/embeddings](https://docs.voyageai.com/docs/embeddings)
223+
224+
```python
225+
import os
226+
227+
from unstructured.documents.elements import Text
228+
from unstructured.embed.voyageai import VoyageAIEmbeddingConfig, VoyageAIEmbeddingEncoder
229+
230+
embedding_encoder = VoyageAIEmbeddingEncoder(
231+
config=VoyageAIEmbeddingConfig(
232+
api_key=os.environ["VOYAGE_API_KEY"],
233+
model_name="voyage-law-2"
234+
)
235+
)
236+
elements = embedding_encoder.embed_documents(
237+
elements=[Text("This is sentence 1"), Text("This is sentence 2")],
238+
)
239+
240+
query = "This is the query"
241+
query_embedding = embedding_encoder.embed_query(query=query)
242+
243+
[print(e, e.embeddings) for e in elements]
244+
print(query, query_embedding)
245+
print(embedding_encoder.is_unit_vector, embedding_encoder.num_of_dimensions)
246+
247+
```

0 commit comments

Comments
 (0)