Note: All code in this guide uses the official HydraDB Python SDK. Base URL: https://api.hydradb.com. Get your API key at app.hydradb.com.
Prerequisites
Required knowledge: Python basics, REST APIs, environment variablesRequired tools:
- HydraDB API key
- Python 3.11 or 3.12 (
python --version) pip install hydradb-sdk
What You’ll Build
By the end of this cookbook, you’ll be able to:- Ingest documents from multiple data sources (Slack, email, Google Drive, Jira) into a unified HydraDB knowledge base
- Run natural language workplace search across all sources with a single
/querycall - Personalize search results per user by storing and retrieving AI memories
- Generate grounded AI answers from retrieved context using any LLM
Overview
A Glean-like application typically includes these core features:- Universal Search: Search across multiple data sources (documents, emails, chats, etc.)
- Retrieval-Assisted Answers: Generate intelligent answers from retrieved company knowledge
- AI Memories for User Preferences: Remember and adapt to individual user preferences, search patterns, and behavioral patterns
- Data Ingestion: Connect to various apps and services
- Knowledge Graph: Build connections between information
- Security & Access Control: Role-based permissions and data isolation
Architecture Overview
Step 1: Data Ingestion Strategy
1.1 App Connectors Setup
You’ll need to connect to various data sources. Here are recommended approaches:Option A: Using Composio
Composio provides pre-built connectors for popular apps:Option B: Vanilla API Integration
For custom integrations, use the native APIs:1.2 Data Normalization
Create a unified data format for all sources:Important: For optimal performance, limit each batch to a maximum of 20 app sources per request. Send multiple batch requests with an interval of 1 second between each request.
1.3 Batch Upload to HydraDB
Use HydraDB’s batch upload capabilities for efficient data ingestion:
Best Practice: Always verify processing after upload using the /context/status endpoint to ensure your data is properly indexed.
Step 2: Search and Answer Generation
2.1 Universal Search Interface
Create a search interface that queries across all data sources:Note: HydraDB supports filtering bysource_titleandsource_typeusing themetadataparameter. Use these for targeted searches across specific data sources.
2.2 Advanced Search Features
Implement advanced search capabilities:Advanced Features:
mode: Use"thinking"for multi-query retrieval with reranking, or"fast"for single-query retrievalalpha: Controls semantic vs keyword matching (0.0-1.0, or"auto")recency_bias: Prioritizes recent content (0.0-1.0)
2.3 AI Memories and User Preferences
One of the most powerful features of building a Glean-like application with HydraDB is leveraging AI Memories to create truly personalized experiences. HydraDB automatically manages AI memories usingcollection for user-level isolation. This allows your application to remember user preferences, past interactions, and behavioral patterns, making every search and interaction more relevant and efficient.
Understanding AI Memories
HydraDB’s AI memories are dynamic, user-specific profiles that evolve over time. They capture not just what users say, but their intentions, preferences, and unique behaviors. HydraDB automatically manages these memories usingcollection for user-level isolation. This enables your Glean clone to:
- Remember User Preferences: Format preferences, source preferences, search patterns
- Understand Intent: Learn what types of information users typically seek
- Adapt Responses: Tailor answers based on past interactions
- Anticipate Needs: Suggest relevant information before users ask
Implementing AI Memories in Your Search
User Preference Learning
Memory-Enhanced Search Interface
Benefits of AI Memories in Your Glean Clone
- Personalized Search Results: Users get results tailored to their preferences and past behavior
- Faster Information Discovery: The system learns what sources and formats users prefer
- Improved User Experience: Every interaction feels more personal and relevant
- Reduced Cognitive Load: Users don’t need to repeat their preferences or search patterns
- Adaptive Learning: The system continuously improves based on user interactions
- Automatic Management: HydraDB handles memory updates automatically - no manual implementation required
Best Practices for AI Memories
- Respect Privacy: Always give users control over their data and preferences
- Transparency: Show users what preferences are being used and allow them to modify them
- Graceful Degradation: Ensure the system works well even without user history
- Collection Isolation: Use
collectionto isolate user data for personalized experiences - Performance: Cache user profiles to avoid repeated API calls
Step 3: Frontend Implementation
3.1 Search Interface
3.2 Results Display
Step 4: Data Synchronization
4.1 Scheduled Sync Jobs
4.2 Webhook Integration
Step 5: Security and Access Control
5.1 Multi-Tenant Architecture
5.2 Data Privacy and Compliance
Step 6: Performance Optimization
6.1 Caching Strategy
6.2 Rate Limiting
Step 7: Monitoring and Analytics
7.1 Search Analytics
Best Practices and Recommendations
1. Data Ingestion Best Practices
- Batch Processing: Use HydraDB’s batch upload endpoints for efficiency
- Batch Limits: Limit to 20 app sources per request with 1-second intervals between batches
- Incremental Sync: Only sync new/changed data to minimize API calls
- Error Handling: Implement retry logic with exponential backoff
- Processing Verification: Always verify upload processing using
/context/status - Rate Limiting: Respect API rate limits and implement queuing
2. Search Optimization
- Query Preprocessing: Clean and normalize user queries
- Result Ranking: Use
alphaandrecency_biasfor fine-tuning - Metadata Filtering: Use
source_titleandsource_typefor targeted searches - Thinking Mode: Use
mode: "thinking"for complex queries that benefit from multi-query retrieval with reranking - Caching: Cache frequent queries and results
3. Security Considerations
- Data Encryption: Encrypt sensitive data at rest and in transit
- Access Control: Implement role-based access control (RBAC)
- Audit Logging: Log all search queries and data access
- Data Retention: Implement automatic data deletion policies
4. Performance Tips
- Connection Pooling: Reuse HTTP connections
- Async Processing: Use async/await for non-blocking operations
- Memory Management: Implement proper cleanup for large datasets
- Batch Optimization: Respect 20-source batch limits and 1-second intervals
- Processing Verification: Verify uploads to ensure data is properly indexed
- Monitoring: Track response times and error rates
5. User Experience
- Autocomplete: Implement search suggestions
- Faceted Search: Allow filtering by source type, date, author
- Saved Searches: Let users save and share search queries
- Export Results: Allow users to export search results
Deployment Checklist
- Set up authentication and authorization
- Configure data connectors and sync schedules
- Implement error handling and monitoring
- Set up caching and rate limiting
- Configure backup and disaster recovery
- Test with production data volumes
- Set up analytics and reporting
- Document API usage and troubleshooting