-
Notifications
You must be signed in to change notification settings - Fork 1
Add JavaScript SDK API reference with vector storage get method documentation #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
devin-ai-integration
wants to merge
2
commits into
main
from
devin/1753714689-add-vector-get-method-docs
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
--- | ||
title: JavaScript SDK API Reference | ||
description: Complete API reference for the Agentuity JavaScript SDK | ||
--- | ||
|
||
# JavaScript SDK API Reference | ||
|
||
The Agentuity JavaScript SDK provides a comprehensive set of APIs for building AI agents that can process diverse inputs, communicate with each other, and integrate with external services. | ||
|
||
## Agent Context | ||
|
||
The `AgentContext` object provides access to platform services and is available as the third parameter in all agent handler functions. | ||
|
||
### Properties | ||
|
||
- `sdkVersion: string` - The version of the Agentuity SDK | ||
- `devmode: boolean` - Returns true if the agent is running in development mode | ||
- `runId: string` - Unique identifier for the current execution | ||
- `orgId: string` - Organization identifier | ||
- `deploymentId: string` - Deployment identifier | ||
- `projectId: string` - Project identifier | ||
- `agent: AgentConfig` - Agent configuration | ||
- `logger: Logger` - Logging interface | ||
- `tracer: Tracer` - OpenTelemetry tracer | ||
- `agents: ServerAgent[]` - List of all agents in the project | ||
- `kv: KeyValueStorage` - Key-value storage interface | ||
- `vector: VectorStorage` - Vector storage interface | ||
|
||
### Methods | ||
|
||
#### getAgent(params) | ||
|
||
Get a handle to a remote agent that you can invoke. | ||
|
||
**Parameters:** | ||
- `params: GetAgentRequestParams` - Agent identification parameters | ||
|
||
**Returns:** `Promise<RemoteAgent>` | ||
|
||
## Key-Value Storage | ||
|
||
The key-value storage API provides persistent storage with GZIP compression and TTL support. | ||
|
||
### Methods | ||
|
||
#### get(key, defaultValue?) | ||
|
||
Retrieve a value from key-value storage. | ||
|
||
**Parameters:** | ||
- `key: string` - The key to retrieve | ||
- `defaultValue?: Json` - Optional default value if key doesn't exist | ||
|
||
**Returns:** `Promise<Json | null>` | ||
|
||
#### set(key, value, ttl?) | ||
|
||
Store a value in key-value storage. | ||
|
||
**Parameters:** | ||
- `key: string` - The key to store | ||
- `value: Json` - The value to store | ||
- `ttl?: number` - Optional time-to-live in seconds | ||
|
||
**Returns:** `Promise<void>` | ||
|
||
#### delete(key) | ||
|
||
Delete a value from key-value storage. | ||
|
||
**Parameters:** | ||
- `key: string` - The key to delete | ||
|
||
**Returns:** `Promise<boolean>` | ||
|
||
## Vector Storage | ||
|
||
The vector storage API provides semantic search capabilities with embedding operations. | ||
|
||
### Methods | ||
|
||
#### upsert(name, ...documents) | ||
|
||
Insert or update vectors in the vector storage. | ||
|
||
**Parameters:** | ||
- `name: string` - The name of the vector storage | ||
- `documents: VectorUpsertParams[]` - The documents to upsert | ||
|
||
**Returns:** `Promise<string[]>` - Array of vector IDs that were upserted | ||
|
||
**Example:** | ||
```javascript | ||
const ids = await context.vector.upsert('my-docs', { | ||
key: 'doc-1', | ||
document: 'This is a sample document', | ||
metadata: { category: 'example' } | ||
}); | ||
``` | ||
|
||
#### get(name, key) | ||
|
||
Retrieve a specific vector by its key from the vector storage. | ||
|
||
**Parameters:** | ||
- `name: string` - The name of the vector storage | ||
- `key: string` - The key of the vector to retrieve | ||
|
||
**Returns:** `Promise<VectorSearchResult | null>` - The vector data including document content, or null if not found | ||
|
||
**Example:** | ||
```javascript | ||
// First, search for relevant vectors | ||
const searchResults = await context.vector.search('my-docs', { | ||
query: 'sample query', | ||
limit: 5 | ||
}); | ||
|
||
// Then retrieve the full document content for each result | ||
const documents = await Promise.all( | ||
searchResults.map(async (result) => { | ||
const vector = await context.vector.get('my-docs', result.key); | ||
return vector ? vector.document : null; | ||
}) | ||
); | ||
``` | ||
|
||
#### search(name, params) | ||
|
||
Search for vectors in the vector storage using semantic similarity. | ||
|
||
**Parameters:** | ||
- `name: string` - The name of the vector storage | ||
- `params: VectorSearchParams` - Search parameters including query, limit, and filters | ||
|
||
**Returns:** `Promise<VectorSearchResult[]>` - Array of search results with similarity scores | ||
|
||
**Example:** | ||
```javascript | ||
const results = await context.vector.search('my-docs', { | ||
query: 'artificial intelligence', | ||
limit: 10, | ||
similarity: 0.7, | ||
metadata: { category: 'tech' } | ||
}); | ||
``` | ||
|
||
#### delete(name, ...ids) | ||
|
||
Delete vectors from the vector storage. | ||
|
||
**Parameters:** | ||
- `name: string` - The name of the vector storage | ||
- `ids: string[]` - Array of vector IDs to delete | ||
|
||
**Returns:** `Promise<number>` - Number of vectors that were deleted | ||
|
||
**Example:** | ||
```javascript | ||
const deletedCount = await context.vector.delete('my-docs', 'doc-1', 'doc-2'); | ||
``` | ||
|
||
## Agent Request | ||
|
||
The `AgentRequest` object encapsulates incoming data and metadata for agent processing. | ||
|
||
### Properties | ||
|
||
- `trigger: string` - The trigger type of the request (webhook, cron, email, etc.) | ||
|
||
### Methods | ||
|
||
#### metadata(key, defaultValue?) | ||
|
||
Get metadata from the request. | ||
|
||
**Parameters:** | ||
- `key: string` - The metadata key | ||
- `defaultValue?: Json` - Optional default value | ||
|
||
**Returns:** `Json` | ||
|
||
#### json() | ||
|
||
Get the request payload as a JSON object. | ||
|
||
**Returns:** `Json` | ||
|
||
#### text() | ||
|
||
Get the request payload as a string. | ||
|
||
**Returns:** `string` | ||
|
||
#### binary() | ||
|
||
Get the request payload as an ArrayBuffer. | ||
|
||
**Returns:** `ArrayBuffer` | ||
|
||
## Agent Response | ||
|
||
The `AgentResponse` object provides methods for constructing various response types. | ||
|
||
### Methods | ||
|
||
#### json(data, metadata?) | ||
|
||
Return a JSON response. | ||
|
||
**Parameters:** | ||
- `data: Json` - The response data | ||
- `metadata?: Record<string, Json>` - Optional response metadata | ||
|
||
**Returns:** `AgentResponseType` | ||
|
||
#### text(data, metadata?) | ||
|
||
Return a text response. | ||
|
||
**Parameters:** | ||
- `data: string` - The response text | ||
- `metadata?: Record<string, Json>` - Optional response metadata | ||
|
||
**Returns:** `AgentResponseType` | ||
|
||
#### redirect(agent, payload?, contentType?, metadata?) | ||
|
||
Redirect the request to another agent. | ||
|
||
**Parameters:** | ||
- `agent: GetAgentRequestParams` - Target agent identification | ||
- `payload?: Json | ArrayBuffer | string` - Optional payload to pass | ||
- `contentType?: string` - Optional content type | ||
- `metadata?: Record<string, Json>` - Optional metadata | ||
|
||
**Returns:** `AgentRedirectResponse` | ||
|
||
## Types | ||
|
||
### VectorUpsertParams | ||
|
||
Parameters for upserting vectors. | ||
|
||
```typescript | ||
interface VectorUpsertParams { | ||
key: string; | ||
document: string; | ||
metadata?: Record<string, Json>; | ||
embedding?: number[]; | ||
} | ||
``` | ||
|
||
### VectorSearchParams | ||
|
||
Parameters for vector search operations. | ||
|
||
```typescript | ||
interface VectorSearchParams { | ||
query: string; | ||
limit?: number; | ||
similarity?: number; | ||
metadata?: Record<string, Json>; | ||
} | ||
``` | ||
|
||
### VectorSearchResult | ||
|
||
Result from vector search operations. | ||
|
||
```typescript | ||
interface VectorSearchResult { | ||
id: string; | ||
key: string; | ||
similarity: number; | ||
metadata?: Record<string, Json>; | ||
document?: string; | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter description for
vector.delete()
contradicts the signatureThe signature is shown as
delete(name, ...ids)
(rest parameters), yet the parameter list describes a single argumentids: string[]
.Either change the bullet to reflect a rest-parameter or adjust the signature to accept an array, but they must match.
📝 Committable suggestion
🤖 Prompt for AI Agents