A Discord bot that provides AI-powered conversation search and retrieval capabilities. Built with Python, discord.py, Supabase, FAISS, and the Google Generative AI (Gemini API), Quiry leverages high-dimensional vector embeddings to enable Retrieval-Augmented Generation (RAG) for dynamic, context-driven responses.
-
Real-time Message Processing
- Automatically captures and processes messages from all channels once deployed
- Groups messages into semantic chunks for efficient storage
- Maintains conversation context and metadata
-
Advanced Search Capabilities
- Semantic search across server history
- Context-aware responses using RAG
- Time-based filtering and relevance ranking
-
Scalable Architecture
- Manages hundreds of thousands of messages across multiple servers using Supabase for reliable data storage
- Efficient vector similarity search with FAISS
- Real-time message processing and embedding generation
-
Message Collection
- Quiry listens for new messages, converts them into vector embeddings (via the Gemini API), and stores them in Supabase
- Messages are grouped into chunks of 10 for efficient processing
- Each chunk maintains metadata including server, channel, and timestamp information
-
Ask Questions
- Use the
/askcommand to retrieve contextually similar past conversations - Quiry's advanced RAG system provides intelligent responses based on your server's history
- Use the
-
Admin Commands
/clear X– Remove the most recent X messages from your server's database (useful for data reset or privacy)/invite– Get the bot's invite link
- Click the link above.
- Select the Discord server you want to add Quiry to.
- Grant the necessary permissions (e.g., reading message history).
- Quiry will join your server and begin indexing messages automatically.
- Monitor and Store Messages
- Quiry listens for new messages, converts them into vector embeddings (via the Gemini API), and stores them in Supabase.
- Ask Questions
- Use the
/askcommand to retrieve contextually similar past conversations. Quiry's advanced RAG system provides intelligent responses based on your server's history.
- Use the
- Admin Commands (optional)
/clear X– Remove the most recent X messages from your server's database (useful for data reset or privacy)./fetch X– (Currently Disabled) Backfill up to X historical messages from your server's channels, giving Quiry a larger data set for retrieval.
- Language & Libraries
- Python, discord.py
- Supabase
- NumPy, FAISS
- Google Generative AI (Gemini API)
- Core Concepts
- Vector Embeddings for chat messages
- Semantic Similarity Search using FAISS
- Retrieval-Augmented Generation (RAG) for context-aware answers
- Architecture
- Message Logging: Listens to messages in real time.
- Embedding Generation: Gemini API transforms each message into a high-dimensional vector.
- Indexing & Storage: Embeddings stored in Supabase and indexed with FAISS.
- Response Generation: When asked, Quiry fetches the most similar embeddings, forms a context, and produces a relevant response.
- By adding Quiry to your server, you grant permission for message data to be stored and processed for semantic retrieval and context-aware responses.
If you have questions or need support, you can contact the bot's owners:
- Discord:
[pppravin],[alexwang06] - Email:
[pravin.lohani23@gmail.com],[wangalex0140@gmail.com]
Quiry is continually evolving to offer better search and AI-driven insights for your community. Feedback and suggestions are always welcome!
-
Message Processing Pipeline
Discord Message → Buffer → Chunk → Embedding → Supabase
- Messages are collected in memory buffers (10 messages per chunk)
- Each chunk is processed into a single document with metadata
- Google's Gemini text-embedding-004 generates vector embeddings
- Data is stored in Supabase with vector support
-
Search & Retrieval System
User Query → Embedding → FAISS Search → Cosine Similarity → Context → GPT-4
- FAISS (Facebook AI Similarity Search) for efficient vector similarity
- Two-stage ranking: FAISS for initial retrieval, cosine similarity for reranking
- Context window of top 5 most relevant message chunks
message_chunks {
id: uuid
server_id: text
channel_id: text
text_message: text
embedding: vector(768) // Gemini embedding dimension
timestamp: timestamp
category: text
message_count: integer
}-
Chunking Strategy
- 10 messages per chunk to balance context and granularity
- Chunks preserve conversation flow while reducing storage overhead
- Metadata includes earliest timestamp for accurate time references
-
Vector Search Implementation
# FAISS Index Creation embedding_dimension = embeddings.shape[1] index = faiss.IndexFlatL2(embedding_dimension) index.add(embeddings)
- L2 (Euclidean) distance for initial retrieval
- Cosine similarity for final ranking
- Configurable top-k retrieval (default: 5)
-
Embedding Generation
def generate_embedding(text): response = gen.embed_content( model="models/text-embedding-004", content=text, task_type="retrieval_document" ) return response["embedding"]
- Uses Google's Gemini text-embedding-004 model
- 768-dimensional vectors
- Optimized for semantic similarity and retrieval tasks
-
Response Generation
def generate_response(query, server_id, top_k=5): # Load and search embeddings index, all_docs, text_map = load_embeddings(server_id) relevant_chunks = search_similar_messages(query, index, all_docs, text_map) # Generate response with GPT-4 response = client.chat.completions.create( model="gpt-4", messages=[...] )
- GPT-4 for high-quality responses
- Structured prompt for consistent formatting
- Dynamic time reference calculation
-
Buffer System
conversation_buffers = {} CHUNK_SIZE = 10
- In-memory buffering for real-time processing
- Server-channel specific buffers
- Automatic chunking when buffer size threshold reached
-
Data Flow
Message → Buffer Buffer (size >= CHUNK_SIZE) → Process Chunk Process Chunk → Generate Embedding Embedding + Metadata → Supabase
-
Initial Retrieval (FAISS)
distances, indices = index.search(query_embedding_np, top_k)
- Fast approximate nearest neighbor search
- L2 distance for initial candidate selection
-
Reranking (Cosine Similarity)
def cosine_sim(query_vec, doc_vec): dot_val = sum(q*d for q, d in zip(query_vec, doc_vec)) doc_norm = sqrt(sum(d*d for d in doc_vec)) return dot_val / (query_norm * doc_norm + 1e-9)
- Cosine similarity for semantic relevance
- Normalized dot product for better accuracy
- Epsilon term (1e-9) to prevent division by zero
-
Structured Output
- Author citations with timestamps
- Relative time references
- Bullet points for multiple facts
- Clear handling of missing information
-
Safety Measures
- Content flagging system
- User ID obfuscation
- Explicit handling of unsafe content
-
Optimizations
- Chunking reduces storage and processing overhead
- FAISS enables fast similarity search
- Cosine similarity reranking improves accuracy
- Buffer system prevents excessive API calls
-
Scalability
- Server-specific data partitioning
- Efficient vector storage in Supabase
- Configurable chunk sizes
- Adjustable top-k retrieval
- Backend: Python 3.12
- AI/ML:
- Google Gemini API (text-embedding-004 for embeddings)
- OpenAI API (GPT-4 for response generation)
- FAISS for vector similarity
- Database: Supabase (PostgreSQL with vector support)
- Bot Framework: Discord.py
- Vector Operations: NumPy
- Environment: Python virtual environment
This architecture enables efficient storage, retrieval, and generation of responses based on Discord server conversations while maintaining scalability and performance.