Create chat API endpoint that processes user queries, performs RAG-based memory retrieval, and handles basic action execution (save memory). Include conversation context management. Design in a way that works with self-hosted models. Provide comprehensive unit tests.