Klu Context
Context is a library of Documents. Klu automatically creates a vector index and performs retrieval augmented generation via similarity search. Klu appends the most relevant documents to the Action prompt at runtime.
Context and Document model
Create Context libraries in Klu Studio and via the API or SDK. Documents are automatically created via Klu Studio (crawler, file upload, or integrations) or programmatically via the API or SDK (app data or file upload).
Documents can be added to a Context library at any time. Klu automatically transcribes audio and video content. Klu supports the following file types:
Category | File Type Extensions |
---|---|
Audio / Video | .mp3, .mp4 |
Documents | .pdf, .rtf, .txt |
eBooks | .epub |
Email Files | .eml, .msg |
Images | .png, .jpg |
Markup/Structured Text | .md, .html, .rst, .org, .xml |
Office Documents | .doc, .docx, .xlsx, .xls, .ppt, .pptx, .odt |
Structured Data | .csv, .tsv |
Additionally, Klu supports non-file Context
Category | Supported Formats |
---|---|
Collaboration | Google, MS Teams, Slack, Zoom |
Customer Platforms | Intercom, Salesforce, Zendesk |
Projects | Airtable, Asana, Atlassian, Github, Notion |
Websites (Crawling) | HTML, Sitemap |
SQL Database | MySQL, PostgreSQL, SQLite, Oracle, SQL Server |
Redis | All data types (string, list, set, zset, hash) |
Elastic | All data types |
Snowflake | All data types |
Youtube | All video formats |
All Context libraries and Documents are automatically associated with the connected Workspace via your API Key.
Context Examples
Here are common examples for how to use Klu Context in your applications.
Create Context from App Data
Create Context from app data in two steps. First, create a custom type Context. Then, add Documents to the Context library. Add specific metadata to each Document to improve retrieval augmented generation results.
Create Context
from klu import Klu
klu = Klu("YOUR_TOKEN")
contect = await klu.context.create(
name="A beautiful library",
description="A library of secret documents",
type="api"
)
print(context)
Add Docs
from klu import Klu
klu = Klu("YOUR_TOKEN")
docs = klu.context.add_doc(
context=context.guid,
content="John McAfee is a great guy. He works at Acme Inc. and lives in New York. He loves tacos.",
meta_data={
"organization_id": "3a38-223-8191",
"organization_name": "Acme Inc.",
"user_id": "1c877-069-4201",
"user_name": "John.McAfee@acme.com"
}
)
Create Context from Files
When creating Context from files, you will need to pre-sign the file URL and then upload the file to the pre-signed URL. This is a two-step process for each file. Once finished, simply add the file names to the Context creation request.
The Klu SDKs greatly simplify this process.
Pre-sign URL
from klu import Klu
klu = Klu("YOUR_TOKEN")
presigned_url = await klu.context.presign(
file_name="taco.csv"
)
print(presigned_url)
Upload File
from klu import Klu
from klu.context.models import FileData
klu = Klu("YOUR_TOKEN")
file_upload = klu.context.upload_file(
FileData(file_name="taco.csv, file_path="~/taco.csv")
)
print(file_upload.object_url)
Create Context
from klu import Klu
klu = Klu("YOUR_TOKEN")
context = klu.context.create(
name="A beautiful library",
description="A library of secret documents",
type="files",
files=["taco.csv", "master_plan_final1.pdf", "unlimited_power.txt"]
)
print(context)
Create Context
Create a new Context library, optimizing it for files or app data (custom). Files must be pre-signed and uploaded to AWS S3 bucket.
Required attributes
- Name
name
- Type
- string
- Description
Name
- Name
description
- Type
- string
- Description
Description
- Name
type
- Type
- string
- Description
Files or Custom
Optional attributes
- Name
files
- Type
- Array
- Description
An array of file names already uploaded to Klu
Create Context
from klu import Klu
klu = Klu("YOUR_TOKEN")
context = klu.context.create(
name="A beautiful library",
description="A library of secret documents",
type="files",
files=["taco.csv", "master_plan_final1.pdf", "unlimited_power.txt"]
)
print(context)
Response
{
"name":"A beautiful library",
"description":"A library of secret documents",
"typeId":4,
"loaderId":12,
"workspaceId":1,
"createdAt":"2023-07-30T03:47:22.601000",
"updatedAt":"2023-07-30T03:47:23.002000",
"createdById":"zzz0a0bb694207z22zll69zphp",
"processed":true,
"meta_data":null,
"guid":"11b4e91c-80be-4edc-96fd-a482c7f263bb"
}
Add App Data
An easy way to convert app data into Context documents.
Required attributes
- Name
text
- Type
- string
- Description
Data sent from your app
Optional attributes
- Name
meta_data
- Type
- JSON
- Description
Key-value pairs of meta data to add to the document
Add Documents
from klu import Klu
klu = Klu("YOUR_TOKEN")
doc = klu.context.add_doc(
context="context_guid",
text="John McAfee is a great guy. He works at Acme Inc. and lives in New York. He loves tacos.",
meta_data={
"organization_id": "3a38-223-8191",
"organization_name": "Acme Inc.",
"user_id": "1c877-069-4201",
"user_name": "John.McAfee@acme.com"
}
)
Response
{
"guid": "123e4567-e89b-12d3-a456-426614174000",
"status": "success"
}
Add Files
A simple endpoint to add files to a Context library. Files must be pre-signed and uploaded to AWS S3 bucket.
Required attributes
- Name
files
- Type
- array
- Description
An array of file names
Add Files
from klu import Klu
klu = Klu("YOUR_TOKEN")
context_updated = klu.context.add_files(
context="context_guid",
files=["taco.csv", "master_plan_final1.pdf", "unlimited_power.txt"]
)
print(context_updated)
Response
{
"name": "A beautiful library",
"description": "A library of secret documents",
"createdAt": "2023-01-01T12:00:00Z",
"updatedAt": "2023-01-01T12:01:00Z",
"processed": true,
"meta_data": {
"organization_id": "3a38-223-8191",
"organization_name": "Acme Inc.",
"user_id": "1c877-069-4201",
"user_name": "John.McAfee@acme.com"
},
"guid": "123e4567-e89b-12d3-a456-426614174000"
}