@fragments-sdk/context
v0.4.3
Published
Code intelligence and RAG primitives for design system and codebase indexing
Downloads
1,760
Maintainers
Readme
@fragments-sdk/context
Code intelligence and RAG primitives for codebase indexing and search.
Modules
Chunking (@fragments-sdk/context/chunking)
Split source files into semantically meaningful chunks for embedding.
chunkFile(content, filePath, language)— Auto-selects AST or line-based chunkingchunkByAST(content, filePath, language, grammar)— Tree-sitter AST-aware chunking (preserves functions, classes, etc.)chunkByLines(content, filePath, language)— Sliding-window fallback
AST chunking supports: TypeScript, TSX, JavaScript, Python, Go, Rust, Java.
import { chunkFile } from "@fragments-sdk/context/chunking";
const chunks = await chunkFile(code, "src/auth.ts", "typescript");
// Each chunk has: content, filePath, startLine, endLine, language, symbolName?, scopeChain?Embeddings (@fragments-sdk/context/embeddings)
Generate code-optimized embeddings via Voyage AI.
generateEmbeddings(texts, options)— Batch embed withvoyage-code-3rerankResults(query, documents, options)— Cross-encoder reranking withrerank-2.5
import { generateEmbeddings } from "@fragments-sdk/context/embeddings";
const vectors = await generateEmbeddings(chunks.map(c => c.content), {
apiKey: process.env.VOYAGE_API_KEY!,
inputType: "document",
});Search (@fragments-sdk/context/search)
Post-retrieval utilities for combining and deduplicating results.
reciprocalRankFusion(resultSets)— Merge multiple ranked lists (e.g. vector + keyword)deduplicateChunks(chunks)— Remove near-duplicate results
Indexing (@fragments-sdk/context/indexing)
File filtering, change detection, and language detection.
shouldIndexFile(path, size)— Filter by extension, size, ignored dirsdetectLanguage(path)— Map file extension to language nameresolveChanges(oldFiles, newFiles)— Diff two file trees for incremental re-indexinghashContent(content)— Content hashing for change detection
Install
pnpm add @fragments-sdk/contextRequires Node.js 18+. Tree-sitter WASM grammars are included as dependencies.
