In this paper, we propose a knowledge base Q&A system based on retrieval-enhanced generation (RAG) technology, which significantly improves the semantic comprehension ability and generation quality of the system by integrating bi-directional gated recurrent units (BiGRUs), neural state machines (NSMs), and hybrid RAG indexing optimization methods. To address the gradient decay problem of traditional recurrent neural networks (RNNs), BiGRU extracts deep features of the text through a bidirectional information transfer mechanism, while NSM simulates human causal thinking through probabilistic scene-graph reasoning to enhance the interpretability of the model. The hybrid RAG strategy further combines local knowledge base construction, context fusion and cue sample introduction to achieve dynamic knowledge enhancement. For indexing optimization, the HNSW-PQ composite indexing technique is adopted to significantly reduce the latency and storage overhead of highdimensional vector retrieval. In the complex knowledge base quiz tasks (CWQ and WebQSP), the model F1 scores reach 70.34% and 83.31%, Hits@1 were 73.18% and 85.33% respectively, which are fully ahead of the traditional methods and pre-trained models. The experimental results show that through the semantic reasoning capability of BiGRU-NSM, the dynamic knowledge enhancement of hybrid RAG and the efficient retrieval of HNSW-PQ indexing, the system achieves breakthroughs in multi-hop reasoning, complex semantic parsing and generative accuracy, and provides an efficient, interpretable and adaptable solution for knowledge base quiz tasks.