Skip to content

MLE-23398 Added docs for vector functions #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion docs/managing-documents/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ Starting in the 1.1.0 release, you can reference a
[REST API transaction](https://docs.marklogic.com/REST/client/transaction-management) via the `tx`
argument. See [the guide on transactions](../transactions.md) for further information.

## Writing documents with vector embeddings

When working with vector embeddings in MarkLogic 12, you can significantly reduce document size and improve
indexing performance by encoding vectors as base64 strings before writing them to the database. As of
version 1.3.0, the MarkLogic Python client provides utilities that are compatible with MarkLogic's
built-in `vec:base64-encode` and `vec:base64-decode` functions.

The following example shows how to use the `base64_encode` function in the `marklogic.vectors` module.
The module also contains a `base64_decode` function that can be used after reading a document to obtain
the original vector array.

```python
from marklogic.documents import Document
from marklogic.vectors import base64_encode

embedding = [0.1, 0.2, 0.3, 0.4, 0.5] # Example embedding
encoded_vector = base64_encode(embedding)

document_content = {
"title": "Sample Document",
"content": "This is a document with an embedding",
"embedding": encoded_vector # Store as encoded string
}

doc = Document("/documents/sample-doc.json", document_content, permissions=default_perms)
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable default_perms is used in the example but is not defined or explained. Consider either defining this variable in the example or adding a comment explaining where it comes from, such as referencing earlier documentation sections.

Copilot uses AI. Check for mistakes.

client.documents.write(doc)
```

## Error handling

Expand Down Expand Up @@ -192,4 +219,4 @@ response = client.rows.update(plan, return_response=True)
```

For more information about the Optic Update feature, please see
https://docs.marklogic.com/guide/release-notes/en/new-features-in-marklogic-11-2/optic-update-generally-available.html
https://docs.marklogic.com/guide/release-notes/en/new-features-in-marklogic-11-2/optic-update-generally-available.html