Team Ai
Apppublic

avinn555/typescript-rag

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

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.space

Endpoints

GET /search?q=question

Main search endpoint for querying the TypeScript Book.

Parameters:

  • โ€”q (required): Your question about TypeScript

Response:

json
{
  "answer": "string containing the answer",
  "sources": "referenced documentation files"
}

Example Requests:

  1. 1.Fat Arrow Syntax
bash
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

  1. 1.Boolean Conversion Operator
bash
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:

  1. 1.Go to Settings โ†’ Repository secrets
  2. 2.Add secret: AIPIPE_API_KEY
  3. 3.Space will automatically rebuild

๐Ÿ› ๏ธ How It Works

  1. 1.Content Ingestion: Fetches TypeScript Book chapters from GitHub
  2. 2.Chunking: Splits content into semantic paragraphs
  3. 3.Embedding Generation: Creates vector embeddings using Jina AI
  4. 4.Retrieval: Finds top-K most relevant chunks for each query
  5. 5.Answer Generation: Uses GPT-4o-mini to synthesize precise answers

๐Ÿ“š Data Source

Content from: TypeScript Deep Dive Book by Basarat Ali Syed

๐Ÿงช Testing

python
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.