Package React Docs for AI
Step-by-step guide to creating a searchable RAG library from React documentation
In this tutorial, you’ll create a libragen library from the React documentation. By the end, you’ll have a searchable library that any AI tool can query for accurate React answers.
Time required: ~10 minutes
What you’ll learn:
- Downloading documentation from a repository
- Building a library with custom metadata
- Querying the library from CLI and MCP
- Versioning and updating libraries
Prerequisites
- Node.js 20 or later
- Basic familiarity with the command line
Step 1: Get the React Documentation
First, let’s download the React documentation. The React team maintains their docs as MDX files in their GitHub repository.
# Create a working directorymkdir react-library && cd react-library
# Clone just the docs (sparse checkout)git clone --depth 1 --filter=blob:none --sparse \ https://github.com/reactjs/react.dev.gitcd react.devgit sparse-checkout set src/content/reference src/content/learnYou now have the React reference and learning docs locally.
Step 2: Build the Library
Build a libragen library from the documentation:
libragen build ./src/content \ --name react-docs \ --description "React documentation including hooks, components, and APIs" \ --content-version 19.0.0You’ll see output like:
Processing files... ✓ 142 files processed ✓ 1,847 chunks created ✓ Embeddings generated ✓ Full-text index built
Library saved: react-docs-19.0.0.libragen (12.4 MB)The library is now ready to use.
Step 3: Query from the CLI
Test your library with a query:
libragen query --library react-docs "When should I use useEffect vs useLayoutEffect?"You’ll get results with relevance scores:
Results for: "When should I use useEffect vs useLayoutEffect?"
[0.92] reference/react/useLayoutEffect.md useLayoutEffect is a version of useEffect that fires before the browser repaints the screen. useLayoutEffect can hurt performance. Prefer useEffect when possible...
[0.89] reference/react/useEffect.md useEffect is a React Hook that lets you synchronize a component with an external system. Effects run after render, so they don't block painting...
[0.84] learn/synchronizing-with-effects.md Some components need to synchronize with external systems. For example, you might want to control a non-React component based on React state...Step 4: Use with Your AI Tool
Option A: MCP Integration (Recommended)
Install the MCP server for your AI tool:
npx -y install-mcp @libragen/mcpThis automatically configures Claude Desktop, Cursor, Windsurf, or other MCP-compatible tools. Now you can ask your AI:
“Using my React library, explain the difference between controlled and uncontrolled components”
The AI will search your library and provide accurate, grounded answers.
Option B: Programmatic Access
Use the library in your own code:
import { Searcher, VectorStore } from '@libragen/core';
const store = await VectorStore.open('react-docs');const searcher = new Searcher(store);
const results = await searcher.search('useState best practices', { topK: 5 });
for (const result of results) { console.log(`[${result.score.toFixed(2)}] ${result.source}`); console.log(result.content);}Step 5: Update When React Updates
When a new React version is released, update your library:
# Pull latest docscd react.devgit pull
# Rebuild with new versionlibragen build ./src/content \ --name react-docs \ --content-version 19.1.0Both versions are now available. Query a specific version:
libragen query \ --library react-docs \ --content-version 19.0.0 \ "useEffect cleanup"Step 6: Share Your Library
Option A: Direct File Sharing
The .libragen file is self-contained. Share it via:
- File hosting (S3, GitHub Releases, etc.)
- Direct transfer
- Package registry
Others can install it:
libragen install ./react-docs-19.0.0.libragenOption B: Add to a Collection
Create a collection manifest to bundle related libraries:
{ "name": "frontend-stack", "description": "Frontend development documentation", "libraries": [ { "name": "react-docs", "url": "https://example.com/react-docs-19.0.0.libragen" }, { "name": "typescript-docs", "url": "https://example.com/typescript-docs-5.7.0.libragen" } ]}Others can install the entire collection:
libragen install --collection https://example.com/frontend-stack.jsonTroubleshooting
”Out of memory” during embedding
Large documentation sets may need more memory:
NODE_OPTIONS="--max-old-space-size=8192" libragen build ./docsSlow embedding generation
Use the --batch-size flag to process fewer chunks at once:
libragen build ./docs --batch-size 50Files not being processed
Check that your files have supported extensions (.md, .mdx, .txt, .html). Use --include to add custom patterns:
libragen build ./docs --include "**/*.rst"Next Steps
Now that you’ve built your first library:
- Building Libraries - Advanced options like chunking strategies
- CI Integration - Automate builds on every release
- Collections - Create and publish collection manifests
- API Reference - Use libragen programmatically