avinn555/typescript-rag
0
TechDocs TypeScript Book RAG API
A Retrieval Augmented Generation (RAG) system that provides precise answers to questions about TypeScript by searching through the official TypeScript Book.
๐ฏ Features
- Semantic Search: Uses embeddings to find relevant content
- Context-Aware Answers: Generates precise answers using retrieved documentation
- Source Attribution: Returns source references for transparency
- Fast Retrieval: Pre-computed embeddings for quick searches
๐ API Usage
Base URL
https://YOUR_USERNAME-typescript-rag.hf.spaceEndpoints
GET /search?q=question
Main search endpoint for querying the TypeScript Book.
Parameters:
q(required): Your question about TypeScript
Response:
{
"answer": "string containing the answer",
"sources": "referenced documentation files"
}Example Requests:
- Fat Arrow Syntax
curl "https://YOUR_USERNAME-typescript-rag.hf.space/search?q=What%20does%20the%20author%20affectionately%20call%20the%20=%3E%20syntax?"Expected answer includes: fat arrow
- Boolean Conversion Operator
curl "https://YOUR_USERNAME-typescript-rag.hf.space/search?q=Which%20operator%20converts%20any%20value%20into%20an%20explicit%20boolean?"Expected answer includes: !!
GET /
Returns API information and status.
GET /health
Health check endpoint showing:
- API configuration status
- Number of chunks loaded
- Embedding generation status
๐ Configuration
Required Secret:
- AIPIPE_API_KEY: Your AI Pipe API token
Setup:
- Go to Settings โ Repository secrets
- Add secret:
AIPIPE_API_KEY - Space will automatically rebuild
๐ ๏ธ How It Works
- Content Ingestion: Fetches TypeScript Book chapters from GitHub
- Chunking: Splits content into semantic paragraphs
- Embedding Generation: Creates vector embeddings using Jina AI
- Retrieval: Finds top-K most relevant chunks for each query
- Answer Generation: Uses GPT-4o-mini to synthesize precise answers
๐ Data Source
Content from: TypeScript Deep Dive Book by Basarat Ali Syed
๐งช Testing
import requests
base_url = "https://YOUR_USERNAME-typescript-rag.hf.space"
# Test query
response = requests.get(f"{base_url}/search", params={
"q": "What does the author affectionately call the => syntax?"
})
print(response.json())๐ Technical Stack
- Framework: FastAPI
- Embeddings: Jina AI (jina-embeddings-v3)
- LLM: GPT-4o-mini via OpenRouter
- Retrieval: Cosine similarity search
- Source: TypeScript Book (GitHub)
โก Performance
- Startup: ~30-60 seconds (fetching & embedding content)
- Query Response: ~2-5 seconds
- Chunks Loaded: ~200-500 documentation chunks
- Top-K Retrieval: 5 most relevant chunks per query
๐ Security
- API key stored as repository secret
- CORS enabled for accessibility
- No sensitive data stored or logged
๐ Example Questions
- "What does the author affectionately call the => syntax?"
- "Which operator converts any value into an explicit boolean?"
- "What is the difference between let and const?"
- "How do arrow functions handle the this keyword?"
- "What are ambient declarations in TypeScript?"
๐ License
Educational/demonstration project for TechDocs Inc.
