The routers are dynamic and can be generated as needed. Below is the general structure and usage of the API endpoints.
All requests to the EmbedPG API must include an Authorization
header with a valid Bearer token. You can generate a new API token by running the pnpm generate:token
command.
Example:
Authorization: Bearer <token>
Endpoints available depends on the generated collections and all instruction below is common to all endpoints. There is only one difference between the endpoints and that is the body of the request. When collection is using external embedding you should replace the documents
with the embeddings
in the request body.
This endpoint is used to create a multiple records in a collection.
{
"ids": [
"1"
],
"documents": [
"document" # your document that must be embedded
],
"metadatas": [
{
"key": 1
}
]
}
type CreateRequest = {
ids: string[];
documents: string[];
metadatas?: {[key: string]: string | number | boolean}[];
}
ids
- An array of ids associated with the document.documents|embeddings
- An array of documents|embeddings to be created.metadatas
- An array of metadata associated with the document. Metadata is optional and can be empty.
- 200 OK
[{
"success": true,
"data": {
"key": "7e03b8e6-5049-4842-b574-e2aa264a5de3",
"documentId": "1",
"document": "Document 1",
"metadata": {
"isCurrent": true
},
"createdAt": "2024-05-26T19:10:12.880Z",
"updatedAt": "2024-05-26T19:10:12.880Z"
}
}],
type CreateResponse = {
success: boolean;
data: {
key: string;
documentId: string;
document: string;
metadata: {[key: string]: string | number | boolean};
createdAt: string;
updatedAt: string;
}
}[]
You can add returnEmbeddings=yes
query parameter to return the embeddings in the response.
{
"document": "document",
"documentId": "1",
"metadata": {
"key": 1,
// other metadata fields
}
}
type UpdateRequest = {
document?: string;
documentId?: string;
metadata?: {[key: string]: string | number | boolean};
}
Response is the same as the create response.
- 200 OK
{
"key": "key",
}
Depends on generated collections your search query can be different. Below is the general structure of the search query.
{
"queryText": "query",
"nResults": 10,
"metadata": {
"key": 1
}
}
queryText
- A query string to search for. In case of external embedding, replacequeryText
with yourembeddings
.nResults
- Number of results to return.metadata
- Metadata to filter the search results.
type SearchRequest = {
queryText: string; // or embeddings: number[]
nResults: number;
metadata: {[key: string]: string | number | boolean};
}
- 200 OK
[{
"key": "7e03b8e6-5049-4842-b574-e2aa264a5de3",
"documentId": "1",
"document": "Document 1",
"metadata": {
"isCurrent": true
},
"createdAt": "2024-05-26T19:10:12.880Z",
"updatedAt": "2024-05-26T19:10:12.880Z"
}]
type SearchResponse = {
key: string;
documentId: string;
document: string; // or embeddings: number[]
metadata: {[key: string]: string | number | boolean};
createdAt: string;
updatedAt: string;
}[]
You can add returnEmbeddings=yes
query parameter to return the embeddings in the response.
same as the search response.
Info: Soon we will implement swagger documentation for the API endpoints.