Data Ingest
Antispace provides a powerful data ingestion service that allows apps to embed and store data for semantic search and retrieval.
Data Ingest enables you to create, update, and delete embeddings that can be queried by users through natural language.
Preparation
To use Data Ingest, you first need to obtain a Platform Token in your App Developer settings.
Note: Platform Token is different from the CLI token, they are not interchangeable.
Setup
To use Data Ingest, first import it from the SDK and create a new instance.
Antispace Data Ingest Setup
import { Ingest } from "@antispace/sdk"
const ingest = new Ingest()
export default ingest
By default, Antispace SDK will look for the platform token in ANTISPACE_PLATFORM_TOKEN
. Alternatively, you can pass the token as the first argument to the constructor:
const ingest = new Ingest(yourPlatformToken)
Note: If you are not deploying your app to Antispace, using Data Ingest also requires ANTISPACE_APP_ID
environment variable to be set. Alternatively, you can pass integrationId
as the second argument to the Ingest
constructor.
Usage
Once you set up your environment and created an Ingest instance, you can use it to manage embeddings with the following methods:
Creating Embeddings
Create new embeddings to make your data searchable:
Creating Embeddings
// Create a new embedding
const { antispaceID } = await ingest.create(
'user123', // userID - Antispace user ID provided to your app
{
title: 'Meeting Notes',
content: 'Discussed Q4 roadmap and budget allocations...',
data: {
date: '2024-01-15',
participants: ['Alice', 'Bob', 'Charlie']
}
},
'meeting' // optional type for categorization
)
console.log('Created embedding:', antispaceID)
Updating Embeddings
Update existing embeddings when your data changes:
Updating Embeddings
// Update an existing embedding
const { antispaceID } = await ingest.update(
'antispace_abc123...', // existing antispaceID
'user123', // userID (must match original)
{
title: 'Meeting Notes (Updated)',
content: 'Discussed Q4 roadmap, budget allocations, and new timeline...',
data: {
date: '2024-01-15',
participants: ['Alice', 'Bob', 'Charlie', 'David'],
updated: true
}
},
'meeting' // optional type
)
Deleting Embeddings
Remove embeddings when data is no longer needed:
Deleting Embeddings
// Delete an embedding
const success = await ingest.delete(
'antispace_abc123...', // antispaceID to delete
'user123' // userID (for ownership verification)
)
if (success) {
console.log('Embedding deleted successfully')
}
Data Structure
When ingesting data, structure your payload to maximize indexability:
Recommended Payload Structure
const payload = {
// Primary content for embedding
title: 'Document Title',
content: 'Main text content that will be embedded...',
// Additional data
data: {
category: 'documentation',
tags: ['api', 'tutorial'],
createdAt: new Date().toISOString(),
source: 'user-upload',
// Any other relevant data
}
}
Note: The entire payload is embedded into Antispace Knowledge Map. Structure your data to include both searchable content and useful metadata.
Best Practices
-
User Association: Always associate embeddings with the correct
userID
to ensure proper data isolation and privacy. -
Meaningful Types: Use descriptive types (e.g., 'document', 'note', 'email') to help categorize your data.
-
Structured Payloads: Include both searchable content and metadata to enhance the user experience.
Integration Example
Here's a complete example showing how to integrate Data Ingest into your app:
Complete Integration Example
import { Ingest } from "@antispace/sdk"
const ingest = new Ingest()
export async function saveDocument(userID: string, document: any) {
try {
// Prepare the payload
const payload = {
title: document.title,
content: document.content,
metadata: {
authorId: document.authorId,
createdAt: new Date().toISOString(),
tags: document.tags || [],
wordCount: document.content.split(' ').length
}
}
// Create the embedding
const { antispaceID } = await ingest.create(
userID,
payload,
'document'
)
// Optionally store the antispaceID in your database for future updates/deletions
await saveToDatabase({
documentId: document.id,
antispaceID,
userID
})
return { success: true, antispaceID }
} catch (error) {
console.error('Failed to ingest document:', error)
return { success: false, error: error.message }
}
}