<p align="center"> <img height="100" width="100" alt="LlamaIndex logo" src="https://ts.llamaindex.ai/square.svg" /> </p> <h1 align="center">LlamaIndex.TS</h1> <h3 align="center"> Data framework for your LLM application. </h3>
LlamaIndex.TS is a TypeScript-first data orchestration framework designed to connect large language models with custom data sources. It provides a structured approach to building retrieval-augmented generation (RAG) applications, where LLMs can query and reason over your private documents, databases, and APIs rather than relying solely on their training data.
The package abstracts the complexity of data ingestion, indexing, and retrieval into a coherent pipeline. It handles document loading from 160+ sources, chunks text into semantic units, generates embeddings, stores them in vector databases, and orchestrates queries that combine retrieval with LLM generation. This makes it particularly valuable for applications requiring factual accuracy grounded in specific datasets.
With 94,000+ weekly downloads, LlamaIndex.TS has become a go-to solution for JavaScript developers building chatbots over documentation, question-answering systems for enterprise knowledge bases, and AI assistants that need domain-specific context. The framework's modular architecture allows swapping LLM providers (OpenAI, Anthropic, local models via Ollama) and vector stores without rewriting core logic.
Built as a TypeScript port of the popular Python LlamaIndex library, it runs across Node.js (v20+), Deno, Bun, and experimental edge runtimes. The strongly-typed API surface reduces runtime errors common in LLM applications while maintaining the flexibility to customize every stage of the RAG pipeline.
import { VectorStoreIndex, Document, OpenAI } from 'llamaindex';
import fs from 'fs/promises';
// Configure LLM provider
const llm = new OpenAI({
model: 'gpt-4',
apiKey: process.env.OPENAI_API_KEY
});
// Load and index documents
async function buildSearchIndex() {
const docText = await fs.readFile('./company-handbook.txt', 'utf-8');
const docs = [
new Document({ text: docText, id_: 'handbook' })
];
// Create vector index (generates embeddings automatically)
const index = await VectorStoreIndex.fromDocuments(docs, {
llm
});
return index;
}
// Query the index
async function queryHandbook(question: string) {
const index = await buildSearchIndex();
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query: question
});
console.log('Answer:', response.toString());
console.log('\nSource nodes:', response.sourceNodes?.map(node => ({
score: node.score,
excerpt: node.node.text.slice(0, 100)
})));
}
// Example usage
queryHandbook('What is the remote work policy?');Enterprise Document QA Systems: Index internal wikis, PDFs, Confluence pages, and Slack archives to create a natural language interface for employee knowledge retrieval. The framework handles document parsing, chunking strategies, and semantic search to surface relevant context before generating answers.
Customer Support Chatbots: Build context-aware chat interfaces that query product documentation, help articles, and historical support tickets. The chat engine maintains conversation history while grounding responses in retrieved company-specific information rather than hallucinated generic advice.
Code Documentation Search: Ingest codebases, API references, and technical specs to create developer-facing search tools. Combine keyword and semantic search across multiple programming languages and frameworks, returning precise code snippets with explanations.
Research Paper Analysis: Load academic papers, patents, or medical literature into vector indexes for literature review automation. Query across thousands of documents to find relevant studies, extract methodologies, or compare findings without manual reading.
Multi-Source Data Agents: Create agentic workflows that query SQL databases, call REST APIs, and search vector stores in response to complex user requests. The agent framework orchestrates tool usage and synthesizes results from heterogeneous data sources into coherent responses.
npm install llamaindexpnpm add llamaindexbun add llamaindex