Documents
This guide will get you all set up and ready to use Superagent Documents. Superagent allows users to do question answering over documents by attaching a Document to an Agent. Documents are files, such as PDF, TXT, images, Markdown etc. that can be ingested by passing a publicly available URL to the Superagent API. Superagent splits these documents into smaller chunks and stores them in a vector database for use downstream.
This approach has some downsides when working with tabular data. We are looking into how to best approach this problem.
The Document Models
The Superagent Swift SDK comes with publicly available models. This makes it easy for you to configure your requests correctly. Documents in superagent allow the following properties in the request.
Document Model
- Name
name
- Type
- String
- Description
The Document name.
- Name
type
- Type
- string
- Description
The document type. Options:
TXT
,PDF
,YOUTUBE
,CSV
,URL
.
- Name
url
- Type
- String
- Description
A publicly available
URL
for the document.
- Name
authorization
- Type
- Any?
- Description
Any authorization/authentication needed to access the document.
- Name
fromPage
- Type
- Int?
- Description
The first page to ingest.
- Name
toPage
- Type
- Int?
- Description
The last page to ingest.
- Name
toPage
- Type
- Int?
- Description
The last pa
- Name
splitter
- Type
- Any?
- Description
The desired text splitter for the document, defaults to CharacterTextSplitter.
Splitter Model
The Splitter Model is a child model of Document which is required inside of the splitter property of the Documents model
- Name
type
- Type
- string
- Description
Valid options,
character
,recursive
,token
,spacy
,nltk
,huggingface
.
- Name
chunkSize
- Type
- Int?
- Description
The chunk size of the text splitter.
- Name
chunkOverlap
- Type
- Any?
- Description
The chunk overlap of the text splitter.
List all Documents
This endpoint allows you to retrieve a list of all your Documents
myDocuments.swift
do {
let myDocuments = try await superagent.listDocuments()
print("Document: \(myDocuments)")
} catch {
print("Error when creating agent: \(error)")
throw error
}
You can access the response key value pairs by requesting a specific key. For example myDocuments["id"]
for the Document Id
Response
{[
{
"id": "clhnyae1t00016i2ixo0027c5",
"userId": "clhj28u1300006ig02ptpm1sh",
"user": {},
"type": "PDF",
"url": "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update",
"createdAt": "2023-05-14T21:50:59.349000+00:00",
"updatedAt": "2023-05-14T21:50:59.349000+00:00",
"index": null,
"Agent": null
}
]
}
Get Document
This endpoint allows you to retrieve a single Document
Require attributes
- Name
id
- Type
- string
- Description
The id of the Document.
myDocuments.swift
do {
let myDocuments = try await superagent.getDocument(id: "myDocumentId")
print("Document: \(myDocuments)")
} catch {
print("Error when creating agent: \(error)")
throw error
}
You can access the response key value pairs by requesting a specific key. For example myDocuments["id"]
for the Document Id
Response
{
"id": "clhnyae1t00016i2ixo0027c5",
"userId": "clhj28u1300006ig02ptpm1sh",
"user": {},
"name": "My document"
"type": "PDF",
"url": "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update",
"createdAt": "2023-05-14T21:50:59.349000+00:00",
"updatedAt": "2023-05-14T21:50:59.349000+00:00",
"index": null,
"Agent": null
}
Create Document
This endpoint allows you to update a single Document
Require attributes
- Name
Document(name "My document", type: "PDF"...)
- Type
- Document Model
- Description
The updated Document as a Document model
myDocuments.swift
let newDocument = Document(name: "My document", type: "PDF", url: "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update", authorization: null, splitter: null)
do {
let myDocuments = try await superagent.createDocument(Document: newDocument)
print("Document: \(myDocuments)")
} catch {
print("Error when creating agent: \(error)")
throw error
}
You can access the response key value pairs by requesting a specific key. For example myDocuments["id"]
for the Document Id
Response
{
"id": "clhnyae1t00016i2ixo0027c5",
"userId": "clhj28u1300006ig02ptpm1sh",
"user": {},
"type": "PDF",
"url": "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update",
"createdAt": "2023-05-14T21:50:59.349000+00:00",
"updatedAt": "2023-05-14T21:50:59.349000+00:00",
"index": null,
"Agent": null
}
Delete Document
This endpoint allows you to retrieve a single Document. The delet function returns a simple true or false boolean value
Require attributes
- Name
id
- Type
- string
- Description
The id of the Document.
myDocuments.swift
do {
let myDocuments = try await superagent.deleteDocument(id: "myDocumentId")
print("Document: \(myDocuments)")
} catch {
print("Error when creating agent: \(error)")
throw error
}