Experimental API - Context Engine SDK is experimental and subject to breaking changes.
DirectContext
This class provides explicit file indexing via API calls with the ability to import and export state to avoid re-indexing between sessions.
Examples
Example 1: Simple Usage
Upload files and ask questions immediately:
Example 2: Persistent Index
Persist state between sessions to avoid re-indexing. This is useful when you want to save the index state to disk and reload it later without having to re-upload and re-index all files. The saved state file contains metadata about which files are indexed, allowing you to resume from where you left off:
Example 3: Batch Upload Then Wait
When you need to upload many files in multiple batches, you can optimize performance by uploading all files first without waiting for indexing, then waiting once at the end. This approach is faster than waiting for indexing after each batch:
Example 4: Custom Prompts
Use searchAndAsk with custom prompts for diverse tasks:
Example 5: External LLM Integration
Use search() results with external LLM APIs:
API Reference
DirectContext.create()
Create and initialize a new DirectContext instance.
Parameters:
options - Optional configuration object
apiKey - API key for authentication (optional)
apiUrl - API URL for your tenant (optional)
debug - Enable debug logging (optional, default: false)
Authentication Priority:
options.apiKey / options.apiUrl (passed to create())
AUGMENT_SESSION_AUTH environment variable (session JSON from auggie token print)
~/.augment/session.json (created by auggie login)
Usage: See complete examples above for full implementation details.
Notes:
- The SDK is source-agnostic - you provide files as
{path, contents} objects
- Files larger than 1MB are rejected during indexing
- All indexing operations are serialized to ensure consistency
- State can be saved and loaded to avoid re-indexing
DirectContext.importFromFile() / import_from_file()
Create a DirectContext instance from a saved state file.
Parameters:
filePath / file_path - Path to the saved state file
options - Optional configuration object (same as create())
Returns: A DirectContext instance with restored state
Usage:
DirectContext.import() / import_state()
Create a DirectContext instance from a saved state object.
Parameters:
state - The state object to restore from
options - Optional configuration object (same as create())
Returns: A DirectContext instance with restored state
Usage:
DirectContext Methods
addToIndex() / add_to_index()
Add files to the index. Files can come from any source - memory, disk, API, database, etc.
Parameters:
files - Array/list of file objects with path and contents
options / wait_for_indexing - Optional configuration
waitForIndexing / wait_for_indexing - If true (default), waits for the newly added files to be indexed before returning
Returns: IndexingResult object with details about what was indexed
Notes:
- Files larger than 1MB will throw an error
- By default, waits for backend indexing to complete before returning (set
waitForIndexing: false / wait_for_indexing=False to return immediately after upload)
- If a file with the same path already exists, it will be updated
- All operations are serialized to ensure consistency
- The SDK optimizes uploads by checking which blobs the server already has and only uploading missing ones
removeFromIndex() / remove_from_index()
Remove files from the index by path.
Parameters:
paths - Array/list of file paths to remove
clearIndex() / clear_index()
Clear the entire index, removing all files.
getIndexedPaths() / get_indexed_paths()
Get the list of currently indexed file paths.
Returns: Array/list of relative file paths that are currently indexed
Use Cases:
- Display indexed files to users
- Verify which files are included in the index
- Filter files for targeted searches
search()
Search the codebase and return formatted results as a string.
Parameters:
query - Natural language search query
options / max_output_length - Optional search options
maxOutputLength / max_output_length - Maximum character length of the formatted output (default: 20000, max: 80000)
Returns: Formatted string containing the search results, ready for LLM consumption
Notes:
- Returns a formatted string designed for use in LLM prompts
- The format includes file paths, line numbers, and code content
- Does NOT wait for indexing - ensure files are indexed before searching by either:
- Using
addToIndex() / add_to_index() with waitForIndexing: true / wait_for_indexing=True (default)
- Calling
waitForIndexing() / wait_for_indexing() explicitly before searching
- Throws an error if the index is empty
searchAndAsk() / search_and_ask()
Search the indexed codebase and ask an LLM a question about the results.
This is a convenience method that combines search() with an LLM call to answer questions about your codebase.
Parameters:
searchQuery / search_query - The semantic search query to find relevant code (also used as the prompt if no separate prompt is provided)
prompt - Optional prompt to ask the LLM about the search results. If not provided, searchQuery is used as the prompt.
Returns: The LLM’s answer to your question
Notes:
- Does NOT wait for indexing - ensure files are indexed before searching by either:
- Using
addToIndex() / add_to_index() with waitForIndexing: true / wait_for_indexing=True (default)
- Calling
waitForIndexing() / wait_for_indexing() explicitly before searching
- Requires authentication via
auggie login, AUGMENT_SESSION_AUTH environment variable, or API credentials for LLM access
Use Cases:
- Quick Q&A about your codebase
- Building conversational interfaces
- Automated code analysis and documentation
waitForIndexing() / wait_for_indexing()
Wait for all indexed files to be fully indexed on the backend.
This method polls the backend until all files that have been added to the index are confirmed to be indexed and searchable.
Returns: Promise that resolves when all files are indexed
Notes:
- Throws an error if indexing times out (default: 10 minutes)
- Only waits for files that have been added to the index
- Useful when you want to control when to wait for indexing completion
Use Cases:
- Batch upload multiple files quickly, then wait for all to be indexed
- Ensure search results include all recently added files
- Control timing of indexing waits in complex workflows
exportToFile() / export_to_file()
Export the current state to a file.
Parameters:
filePath / file_path - Path to save the state file
Use Cases:
- Persist indexing state between sessions
- Avoid re-indexing large codebases
- Share indexing state across different processes
export()
Export the current state as an object (in-memory).
Returns: State object that can be serialized and stored
FileSystemContext
This class provides automatic indexing and search capabilities for a local directory.
FileSystemContext.create()
Create and initialize a new FileSystemContext instance.
Parameters:
options / positional args - Configuration
directory - Path to the workspace directory to index (required)
auggiePath / auggie_path - Path to auggie executable (optional, default: “auggie”)
debug - Enable debug logging (optional, default: false)
Usage: See DirectContext examples above for similar patterns.
Notes:
- Automatically indexes the directory on startup
- Requires
auggie CLI to be installed and accessible
- Python supports context manager (
with statement) for automatic cleanup
FileSystemContext Methods
search()
Search the codebase and return formatted results as a string.
Parameters:
query - Natural language search query
Returns: Formatted string containing the search results, ready for LLM consumption
searchAndAsk() / search_and_ask()
Search the indexed codebase and ask an LLM a question about the results.
Parameters:
searchQuery / search_query - The semantic search query to find relevant code (also used as the prompt if no separate prompt is provided)
prompt - Optional prompt to ask the LLM about the search results. If not provided, searchQuery is used as the prompt.
Returns: The LLM’s answer to your question
Notes:
- Requires authentication via
auggie login, AUGMENT_SESSION_AUTH environment variable, or API credentials for LLM access
close()
Close the connection and cleanup resources.
Notes:
- Always call
close() when done to cleanup resources
- Python: Use context manager (
with statement) for automatic cleanup
Types
File
Represents a file to be indexed (input type for addToIndex() / add_to_index()).
IndexingResult
Result from addToIndex() / add_to_index() operation showing what was indexed.
Notes:
newlyUploaded / newly_uploaded: Files that were uploaded to the server and indexed
alreadyUploaded / already_uploaded: Files that were skipped because:
- They were already in the local cache with the same content, OR
- The server already had the blob (detected via
find-missing API)
DirectContextOptions (TypeScript) / Keyword Arguments (Python)
Options for configuring DirectContext.
DirectContextState
State for DirectContext that can be saved/loaded.
Serialization Example:
FileSystemContextOptions (TypeScript) / Keyword Arguments (Python)
Options for FileSystem Context.
Authentication
The SDK automatically loads credentials from multiple sources in this priority order:
- Options/keyword arguments:
apiKey/api_key and apiUrl/api_url passed to DirectContext.create()
- Environment variable:
AUGMENT_SESSION_AUTH (session JSON from auggie token print)
- Session file:
~/.augment/session.json (created by auggie login)
To get credentials:
- Sign in to Augment using the CLI:
auggie login
- Your credentials will be stored in
~/.augment/session.json
- The SDK will automatically use them
Error Handling
The SDK exports specific error classes for better error handling: