Overview
createCtxWindow() creates a context window and registers it in the global registry. This allows you to retrieve the instance later using getCtxWindow() without passing it around your application.
Use this when you need to access the same context window from multiple modules or functions.
Signature
Parameters
Configuration object for the context windowThe
namespace serves as both the Pinecone namespace and the registry key.See Configuration documentation for detailed parameter descriptions.
Return Value
createCtxWindow() returns a Promise that resolves to void. The created instance is stored in the registry and can be retrieved using getCtxWindow().
Registry Pattern
The registry pattern is useful for applications with multiple context windows or when you need to access instances across different modules.Examples
Basic Usage
Multiple Context Windows
API Route Example (Express)
Modular Application
Best Practices
1. Initialize Early
Create and register context windows during application startup:2. Use Descriptive Names
Choose clear, descriptive index names:3. Check Existence
Before creating, check if a context window already exists:4. Cleanup When Done
Remove context windows when they’re no longer needed:Error Handling
Utility Functions
The registry pattern works with several utility functions:getCtxWindow()
Retrieve a registered context window
hasCtxWindow()
Check if a context window exists
deleteCtxWindow()
Remove a context window from registry
listCtxWindows()
Get all registered index names
When to Use
UsecreateCtxWindow() for:
- Accessing the context window from multiple modules
- Building web servers with route handlers
- Managing multiple context windows
- Cleaner code without passing instances around
- Global access to instances across your application
Related
getCtxWindow
Retrieve registered instances
Utility Functions
Registry management functions
ask()
Query context windows
Configuration
Detailed configuration options