Announcing Typescript SDK
A Typescript-native interface for Vectara, simplifying Integration for Developers
4-minute read timeIntroduction
At Vectara, we're dedicated to empowering developers with powerful tools to create GenAI applications using our end-to-end RAG platform. While our Python SDK serves many developers well, we recognize the growing importance of TypeScript in modern web development.
Today, we're excited to announce our TypeScript SDK (in beta), bringing enterprise RAG capabilities to your web applications. Built with modern TypeScript practices in mind. This SDK offers complete type safety while maintaining feature parity with our REST API. Like our Python SDK, it's developed in partnership with Fern (YC W23) and is automatically generated from our OpenAPI spec, ensuring it stays current with our latest features.
TypeScript SDK overview
Our TypeScript SDK provides a natural, typed interface to every operation available in our API. By leveraging TypeScript's type system, we offer enhanced developer experience with:
- Full-type safety and auto-completion
- Runtime type checking
- Reduced potential for runtime errors through compile-time checks
Installing the SDK
You can install the SDK using npm or yarn:
Authentication
To get started with Vectara using the SDK, you first have to set up a client and authenticate against your Vectara account.
The SDK includes built-in support for both the API key and OAuth authentication methods:
1. Authenticate with API Key:
2. Authenticate with OAuth:
Using the SDK
Now you have a client object, let’s see how you can run common operations with this client.
1. Uploading files
Uploading diverse document types is a common requirement for web applications. Vectara's platform supports various formats—including PDFs, DOCX, PPTX, and Markdown—automatically extracting text and segmenting it into semantically meaningful chunks. These segments are then encoded into vectors using Vectara’s Boomerang embedding model, and stored in the internal data store - ready for querying.
To facilitate seamless integration, our SDK provides built-in TypeScript types compatible with both Node.js's Buffer and the browser's Blob interfaces. This ensures that handling file uploads in your web application is straightforward and efficient. Here's how you can manage file uploads.
You can also include metadata that will be associated with your document in the index.
2. Indexing text
With RAG, content is not always just files. It could also be content that is generated dynamically—be it user-generated posts, entries from a Content Management System (CMS), or data fetched from external APIs. It could also be data from other sources like a database, Notion, JIRA, or many others.
Like our API, our SDK offers type-safe interfaces that allow you to index such content directly, without the need for intermediate file storage.
To achieve this, you can construct a StructuredDocument object that encapsulates the sections of your content intended for indexing. Each section can represent a distinct chunk of text and may include associated metadata to enhance search relevance.
Here's an example of how to index dynamically generated content.
This will index the text directly, making the data available for querying immediately.
Note that the SDK also supports core indexing, which provides fine-grained control over the chunking process, using the CoreDocument object instead of StructuredDocument.
3. Executing queries
Once you’ve indexed documents (either through file uploads or direct text indexing), you can run queries against the full Vectara RAG pipeline.
4. Multi-turn chats
Vectara's chat capability provides an integrated memory for chat history that makes it super easy to implement AI assistants and agents with multi-turn conversation sessions.
With the SDK this takes the following form. First, you create a chat session:
Then we can use the chat function to ask a query:
What else is in the SDK?
We have shown specific code examples of using the SDK that cover the basic use of Vectara: indexing documents, running a query, and using chat.
The SDK covers a lot more, and in fact mirrors the full functionality of our API including:
- Corpus management (CRUD operations)
- Document management and retrieval
- Account configuration and management
- User administration
- API key and OAuth client management
- Query history and analytics
Importantly, all query and chat functionality support streaming. Simply replace query() with queryStream(), for example:
Conclusion
The Vectara TypeScript SDK brings the power of a type-safe SDK to our RAG platform. Whether you're building a web application, server-side service, or hybrid solution, our TypeScript SDK provides a robust foundation for your GenAI applications.
Ready to start? Sign up for Vectara's 30-day free trial and experience the power of Vectara RAG. If you're already using Vectara, we'd love to hear your feedback on the TypeScript SDK through our GitHub repository or Discord server.
Happy coding with types! 🚀