The chat widget retrieves the most relevant Help Center articles for a user's question using keyword scoring against a knowledge base (db.jsonl), builds a context block from the top matches, and passes it to an AI model to generate a grounded answer. It also filters profanity and strips prompt-injection attempts from user input before processing.