How leonardo1364/serverless-chat-langchainjs works
This is a serverless RAG support-chat application: users ask questions in a Lit chat UI, the API retrieves document context and streams grounded answers, and citations link back to source PDFs. The documented product also supports PDF ingestion and Azure Blob storage, with Ollama and FAISS alternatives for local use. Sampled handlers establish the chat and document paths; the README documents hosting and storage capabilities, while source for deployment wiring was not sampled.
Main entry points: chat-post.ts Chat endpoint · chat.ts Chat component · api.ts Web API client · documents-post.ts Document upload
Components 19
Chat interface
- Chat component
packages/webapp/src/components/chat.ts - Web API client
packages/webapp/src/api.ts - Message parser
packages/webapp/src/message-parser.ts
Serverless API
- Chat endpoint
packages/api/src/functions/chat-post.ts - Document upload
packages/api/src/functions/documents-post.ts - Document download
packages/api/src/functions/documents-get.ts - HTTP responses
packages/api/src/http-response.ts
Knowledge pipeline
- Source PDFs
data - PDF extraction and chunking
packages/api/src/functions/documents-post.ts - Embedding models
packages/api/src/functions/documents-post.ts - Vector search
packages/api/src/functions/chat-post.ts - Retrieval and prompt chain
packages/api/src/functions/chat-post.ts
Azure platform
- Cosmos vector database
- Local FAISS store
packages/api/src/constants.ts - Blob document storage
- Azure OpenAI or Ollama
packages/api/src/functions/chat-post.ts - Static Web Apps
- Azure Functions
packages/api/src/functions
Other components
- Chat user
Connections 30
- Chat user → Chat component: asks
- Chat component → Web API client: requests completion
- Web API client → Chat endpoint: posts chat
- Chat endpoint → Vector search: retrieves context
- Chat endpoint → Retrieval and prompt chain: runs chain
- Retrieval and prompt chain → Azure OpenAI or Ollama: generates answer
- Vector search → Cosmos vector database: searches vectors
- Vector search → Local FAISS store: searches vectors
- Chat endpoint → Azure OpenAI or Ollama: embeds query
- Chat endpoint → Web API client: streams NDJSON
- Web API client → Chat component: yields chunks
- Chat component → Message parser: parses messages
- Message parser → Chat component: returns citations
- Chat component → Web API client: requests citation URL
- Web API client → Document download: fetches PDF
- Chat user → Document upload: uploads PDF
- Document upload → PDF extraction and chunking: extracts and splits
- PDF extraction and chunking → Embedding models: embeds chunks
- Embedding models → Cosmos vector database: writes vectors
- Embedding models → Local FAISS store: writes vectors
- Document upload → Blob document storage: stores PDF
- Document download → Blob document storage: reads PDF
- Document download → Source PDFs: reads local PDF
- Document upload → HTTP responses: returns status
- Document download → HTTP responses: returns document
- Chat endpoint → HTTP responses: returns stream
- Static Web Apps → Chat component: hosts
- Azure Functions → Chat endpoint: dispatches
- Azure Functions → Document upload: dispatches
- Azure Functions → Document download: dispatches