@@ -164,6 +164,33 @@ Starting in the 1.1.0 release, you can reference a
164164[ REST API transaction] ( https://docs.marklogic.com/REST/client/transaction-management ) via the ` tx `
165165argument. See [ the guide on transactions] ( ../transactions.md ) for further information.
166166
167+ ## Writing documents with vector embeddings
168+
169+ When working with vector embeddings in MarkLogic 12, you can significantly reduce document size and improve
170+ indexing performance by encoding vectors as base64 strings before writing them to the database. As of
171+ version 1.3.0, the MarkLogic Python client provides utilities that are compatible with MarkLogic's
172+ built-in ` vec:base64-encode ` and ` vec:base64-decode ` functions.
173+
174+ The following example shows how to use the ` base64_encode ` function in the ` marklogic.vectors ` module.
175+ The module also contains a ` base64_decode ` function that can be used after reading a document to obtain
176+ the original vector array.
177+
178+ ``` python
179+ from marklogic.documents import Document
180+ from marklogic.vectors import base64_encode
181+
182+ embedding = [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ] # Example embedding
183+ encoded_vector = base64_encode(embedding)
184+
185+ document_content = {
186+ " title" : " Sample Document" ,
187+ " content" : " This is a document with an embedding" ,
188+ " embedding" : encoded_vector # Store as encoded string
189+ }
190+
191+ doc = Document(" /documents/sample-doc.json" , document_content, permissions = default_perms)
192+ client.documents.write(doc)
193+ ```
167194
168195## Error handling
169196
@@ -192,4 +219,4 @@ response = client.rows.update(plan, return_response=True)
192219```
193220
194221For more information about the Optic Update feature, please see
195- https://docs.marklogic.com/guide/release-notes/en/new-features-in-marklogic-11-2/optic-update-generally-available.html
222+ https://docs.marklogic.com/guide/release-notes/en/new-features-in-marklogic-11-2/optic-update-generally-available.html
0 commit comments