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)
import { ZeroEntropy } from 'zeroentropy';
const zclient = new ZeroEntropy();
// Add a document to a new collection
async function addDocument() {
try {
// Add a new collection
await zclient.collections.add({
collection_name: "default",
});
console.log("Collection 'default' created successfully.");
// Add a document to the collection
const response = await zclient.documents.add({
collection_name: "default",
path: "docs/document.txt",
content: {
type: "text",
text: "My favorite apple is the Granny Smith.",
},
metadata: {
timestamp: new Date().toISOString(),
"list:tags": ["tag 1", "tag 2"],
}
});
console.log(response.message);
} catch (error) {
console.error("Error:", error);
}
}
addDocument();
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)
import axios from 'axios';
import { ZeroEntropy } from 'zeroentropy';
const zclient = new ZeroEntropy();
// Add a document to a new collection
async function addPdf() {
try {
// Add a new collection
await zclient.collections.add({
collection_name: "pdfs",
});
console.log("Collection 'pdfs' created successfully.");
// Fetch the document
const documentResponse = await axios.get('https://arxiv.org/pdf/2408.10343.pdf', {
responseType: 'arraybuffer'
});
// Convert document to Base64
const base64Content = Buffer.from(documentResponse.data).toString('base64');
// Add a document to the collection
const response = await zclient.documents.add({
collection_name: "pdfs",
path: "docs/document.pdf",
content: {
type: "auto",
base64_data: base64Content,
},
metadata: {
timestamp: new Date().toISOString(),
"list:tags": ["arxiv", "research"],
}
});
console.log(response.message);
} catch (error) {
console.error("Error:", error);
}
}
addPdf();
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)
import { ZeroEntropy } from 'zeroentropy'
const zclient = new ZeroEntropy()
// Add a document with pages to a new collection
async function addTextPages() {
try {
// Add a new collection
await zclient.collections.add({
collection_name: "pages",
});
console.log("Collection 'pages' created successfully.");
// Upload text with pages for TopK page queries
const response = await zclient.documents.add({
collection_name: "pages",
path: "docs/document_pages.txt",
content: {
type: "text-pages",
pages: [
"page 1 content",
"page 2 content",
],
},
});
console.log(response.message);
} catch (error) {
console.error("Error:", error);
}
}
addTextPages();