Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c476f56
Add initial GenAI module placeholder
renecannao Jan 7, 2026
59f0b8b
Fix GenAI module admin commands - correct character check
renecannao Jan 8, 2026
99dbd0a
Add TAP test for GenAI module
renecannao Jan 8, 2026
5dad625
Add GenAI module prototype
renecannao Jan 8, 2026
89285aa
Add comprehensive Doxygen documentation to genai_demo.cpp
renecannao Jan 8, 2026
11d183a
Add event-driven GenAI demo
renecannao Jan 8, 2026
012142e
Fix event-driven GenAI demo and add early termination
renecannao Jan 8, 2026
2c0f3a2
Evolve genai_demo_event to working POC with real embeddings
renecannao Jan 9, 2026
aa53610
Add batch embedding support and scale up GenAI prototype
renecannao Jan 9, 2026
f0a32c0
Add rerank support to GenAI prototype via llama-server
renecannao Jan 9, 2026
9607040
Implement real GenAI module with embedding and rerank support
renecannao Jan 9, 2026
1da9e38
Add poll() fallback for GenAI module when epoll is not available
renecannao Jan 9, 2026
fa30194
Remove genai_demo_event binary from tracking and update .gitignore
renecannao Jan 9, 2026
b5598d8
Add comprehensive ProxySQL_Poll usage documentation throughout codebase
renecannao Jan 9, 2026
253591d
Add experimental GenAI EMBED: query support for MySQL
renecannao Jan 9, 2026
39939f5
Add experimental GenAI RERANK: query support for MySQL
renecannao Jan 9, 2026
cc3e97b
Merge EMBED and RERANK into unified GENAI: query syntax
renecannao Jan 9, 2026
a82f58e
Refactor GenAI module for autonomous JSON query processing
renecannao Jan 9, 2026
bbad8ab
Fix GenAI variable naming and add comprehensive TAP tests
renecannao Jan 9, 2026
0ff2e38
Implement async GenAI module with socketpair-based non-blocking archi…
renecannao Jan 9, 2026
8405027
Integrate GenAI async event handling into main MySQL session loop
renecannao Jan 10, 2026
db2485b
Add comprehensive doxygen documentation to GenAI async module
renecannao Jan 10, 2026
bdd2ef7
Add comprehensive TAP tests for GenAI async architecture
renecannao Jan 10, 2026
b77d38c
Add comprehensive GenAI module documentation
renecannao Jan 10, 2026
33a87c6
Fix critical issues identified by gemini-code-assist
renecannao Jan 10, 2026
de3fd05
Reverted change to test/tap/tests/.env
renecannao Jan 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
490 changes: 490 additions & 0 deletions doc/GENAI.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions genai_prototype/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build artifacts
genai_demo
genai_demo_event
*.o
*.oo

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Editor files
*~
.*.swp
.vscode/
.idea/

# Core dumps
core
core.*

# Temporary files
*.tmp
*.temp
*.log
83 changes: 83 additions & 0 deletions genai_prototype/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Makefile for GenAI Prototype
# Standalone prototype for testing GenAI module architecture

CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -g
LDFLAGS = -lpthread -lcurl
CURL_CFLAGS = $(shell curl-config --cflags)
CURL_LDFLAGS = $(shell curl-config --libs)

# Target executables
TARGET_THREAD = genai_demo
TARGET_EVENT = genai_demo_event
TARGETS = $(TARGET_THREAD) $(TARGET_EVENT)

# Source files
SOURCES_THREAD = genai_demo.cpp
SOURCES_EVENT = genai_demo_event.cpp

# Object files
OBJECTS_THREAD = $(SOURCES_THREAD:.cpp=.o)
OBJECTS_EVENT = $(SOURCES_EVENT:.cpp=.o)

# Default target (build both demos)
all: $(TARGETS)

# Individual demo targets
genai_demo: genai_demo.o
@echo "Linking genai_demo..."
$(CXX) genai_demo.o $(LDFLAGS) -o genai_demo
@echo "Build complete: genai_demo"

genai_demo_event: genai_demo_event.o
@echo "Linking genai_demo_event..."
$(CXX) genai_demo_event.o $(CURL_LDFLAGS) $(LDFLAGS) -o genai_demo_event
@echo "Build complete: genai_demo_event"

# Compile source files
genai_demo.o: genai_demo.cpp
@echo "Compiling $<..."
$(CXX) $(CXXFLAGS) -c $< -o $@

genai_demo_event.o: genai_demo_event.cpp
@echo "Compiling $<..."
$(CXX) $(CXXFLAGS) $(CURL_CFLAGS) -c $< -o $@

# Run the demos
run: $(TARGET_THREAD)
@echo "Running thread-based GenAI demo..."
./$(TARGET_THREAD)

run-event: $(TARGET_EVENT)
@echo "Running event-based GenAI demo..."
./$(TARGET_EVENT)

# Clean build artifacts
clean:
@echo "Cleaning..."
rm -f $(OBJECTS_THREAD) $(OBJECTS_EVENT) $(TARGETS)
@echo "Clean complete"

# Rebuild
rebuild: clean all

# Debug build with more warnings
debug: CXXFLAGS += -DDEBUG -Wpedantic
debug: clean all

# Help target
help:
@echo "GenAI Prototype Makefile"
@echo ""
@echo "Targets:"
@echo " all - Build both demos (default)"
@echo " genai_demo - Build thread-based demo"
@echo " genai_demo_event - Build event-based demo"
@echo " run - Build and run thread-based demo"
@echo " run-event - Build and run event-based demo"
@echo " clean - Remove build artifacts"
@echo " rebuild - Clean and build all"
@echo " debug - Build with debug flags and extra warnings"
@echo " help - Show this help message"

.PHONY: all run run-event clean rebuild debug help
139 changes: 139 additions & 0 deletions genai_prototype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# GenAI Module Prototype

Standalone prototype demonstrating the GenAI module architecture for ProxySQL.

## Architecture Overview

This prototype demonstrates a thread-pool based GenAI module that:

1. **Receives requests** from multiple clients (MySQL/PgSQL threads) via socket pairs
2. **Queues requests** internally with a fixed-size worker thread pool
3. **Processes requests asynchronously** without blocking the clients
4. **Returns responses** to clients via the same socket connections

### Components

```
┌─────────────────────────────────────────────────────────┐
│ GenAI Module │
│ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Listener Thread (epoll-based) │ │
│ │ - Monitors all client file descriptors │ │
│ │ - Reads incoming requests │ │
│ │ - Pushes to request queue │ │
│ └──────────────────┬─────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Request Queue │ │
│ │ - Thread-safe queue │ │
│ │ - Condition variable for worker notification │ │
│ └──────────────────┬─────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Thread Pool (configurable number of workers) │ │
│ │ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │
│ │ │Worker│ │Worker│ │Worker│ │Worker│ ... │ │
│ │ └───┬──┘ └───┬──┘ └───┬──┘ └───┬──┘ │ │
│ │ └──────────┴──────────┴──────────┘ │ │
│ └────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
▲ │ ▲
│ │ │
socketpair() Responses socketpair()
from clients to clients from clients
```

### Communication Protocol

**Client → GenAI (Request)**:
```cpp
struct RequestHeader {
uint64_t request_id; // Client's correlation ID
uint32_t operation; // 0=embedding, 1=completion, 2=rag
uint32_t input_size; // Size of following data
uint32_t flags; // Reserved
};
// Followed by input_size bytes of input data
```

**GenAI → Client (Response)**:
```cpp
struct ResponseHeader {
uint64_t request_id; // Echo client's ID
uint32_t status_code; // 0=success, >0=error
uint32_t output_size; // Size of following data
uint32_t processing_time_ms; // Time taken to process
};
// Followed by output_size bytes of output data
```

## Building and Running

```bash
# Build
make

# Run
make run

# Clean
make clean

# Debug build
make debug

# Show help
make help
```

## Current Status

**Implemented:**
- ✅ Thread pool with configurable workers
- ✅ epoll-based listener thread
- ✅ Thread-safe request queue
- ✅ socketpair communication
- ✅ Multiple concurrent clients
- ✅ Non-blocking async operation
- ✅ Simulated processing (random sleep)

**TODO (Enhancement Phase):**
- ⬜ Real LLM API integration (OpenAI, local models)
- ⬜ Request batching for efficiency
- ⬜ Priority queue for urgent requests
- ⬜ Timeout and cancellation
- ⬜ Backpressure handling (queue limits)
- ⬜ Metrics and monitoring
- ⬜ Error handling and retry logic
- ⬜ Configuration file support
- ⬜ Unit tests
- ⬜ Performance benchmarking

## Integration Plan

Phase 1: **Prototype Enhancement** (Current)
- Complete TODO items above
- Test with real LLM APIs
- Performance testing

Phase 2: **ProxySQL Integration**
- Integrate into ProxySQL build system
- Add to existing MySQL/PgSQL thread logic
- Implement GenAI variable system

Phase 3: **Production Features**
- Connection pooling
- Request multiplexing
- Caching layer
- Fallback strategies

## Design Principles

1. **Zero Coupling**: GenAI module doesn't know about client types
2. **Non-Blocking**: Clients never wait on GenAI responses
3. **Scalable**: Fixed resource usage (bounded thread pool)
4. **Observable**: Easy to monitor and debug
5. **Testable**: Standalone, independent testing
Loading