Examples
Upload
Examples
Upload
Examples of uploading documents to ZeroEntropy
After creating an API Key and exporting it, you can start uploading documents to your collections. Below are some examples of how to do this using the ZeroEntropy SDK for Python and TypeScript.
Upload a text file
from datetime import datetime
from zeroentropy import ZeroEntropy
zclient = ZeroEntropy()
# Add a new collection
response = zclient.collections.add(collection_name="default")
# Add a document to the collection
response = zclient.documents.add(
collection_name="default",
path="docs/document.txt",
content={
"type": "text",
"text": "My favorite apple is the Granny Smith.",
},
metadata={
"timestamp": datetime.now().isoformat(),
"list:tags": ["tag 1", "tag 2"],
}
)
print(response.message)
Upload a PDF file
import requests
import base64
from datetime import datetime
from zeroentropy import ZeroEntropy
zclient = ZeroEntropy()
# Create new collection
response = zclient.collections.add(
collection_name="pdfs"
)
document = requests.get(
"https://arxiv.org/pdf/2408.10343.pdf"
)
# Convert to base64
base64_content = base64.b64encode(document.content).decode('utf-8')
response = zclient.documents.add(
collection_name="pdfs",
path="docs/document.pdf",
content={
"type": "auto",
"base64_data": base64_content,
},
metadata={
"timestamp": datetime.now().isoformat(),
"list:tags": ["arxiv", "research"],
}
)
print(response.message)
Upload documents with pages
from zeroentropy import ZeroEntropy
zclient = ZeroEntropy()
response = zclient.collections.add(collection_name="pages")
# Upload text with pages, for TopK pages queries
response = zclient.documents.add(
collection_name="pages",
path="docs/document_pages.txt",
content={
"type": "text-pages",
"pages": [
"page 1 content: My favorite apple is the Granny Smith.",
"page 2 content: Search is a fun problem to work on.",
],
},
)
print(response.message)