Skip to main content
Note: Examples use the HydraDB Python and TypeScript SDKs. Base URL: https://api.hydradb.com. Get your API key at app.hydradb.com.

Prerequisites

Required knowledge: Python basics, REST APIs, environment variables
Required 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 /query call
  • 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. The upload helpers require an explicit acl on every source ([] grants access to nobody). Query with principals derived from your authenticated server session. The search helpers below require those principals; see Access Control.
Pacing: The sample sends 20 app sources per batch with a 1-second pause. Split a batch on 413, and honor Retry-After on 429.

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: Source filters below match source_category and source_label in additional_metadata, populated by the upload helpers. They describe the originating app and document title; they are not the built-in source_type field. Keep these search functions on your server, and derive caller_acl / callerAcl from the authenticated session.

2.2 Advanced Search Features

Reuse query_as_caller / queryAsCaller from 2.1 for the searches below.
Advanced Features:
  • mode: Use "thinking" for multi-query retrieval with reranking, or "fast" for single-query retrieval. Omitted means "auto", which picks one per query
  • alpha: Controls semantic vs keyword matching (0.0-1.0, or "auto"). Default 0.8
  • recency_bias: Prioritizes recent content (0.0-1.0). Omitted means a mild 0.4 tilt; send 0 to turn it off

2.3 AI Memories and User Preferences

AI Memories turn a Glean-like application into a personal one. HydraDB isolates each user’s memories in their own collection, so your application can 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. 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
The code below reuses the caller-bound query helper from 2.1, keeps the profile in a local store, and folds it into the query text. To keep preferences in HydraDB instead, store them as memories.

User Preference Learning

Memory-Enhanced Search Interface

The UI receives a searchApi(query) function for your authenticated backend. That backend derives the user ID and ACL principals before calling searchWithMemory; keep the HydraDB key on the server.

Benefits of AI Memories in Your Glean Clone

  1. Personalized Search Results: Users get results tailored to their preferences and past behavior
  2. Faster Information Discovery: The system learns what sources and formats users prefer
  3. Improved User Experience: Every interaction feels more personal and relevant
  4. Reduced Cognitive Load: Users don’t need to repeat their preferences or search patterns
  5. Adaptive Learning: The system continuously improves based on user interactions
  6. Automatic Management: HydraDB handles memory updates automatically when you ingest raw interactions as memories with infer: true

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 collection to isolate user data for personalized experiences
  • Performance: Cache user profiles to avoid repeated API calls

Step 3: Frontend Implementation

3.1 Search Interface

Pass a searchApi(query, filters) function that calls your authenticated backend. The backend derives ACL principals from the session and calls searchWithFilters(query, database, callerAcl, filters) from Step 2.2.

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

Run this helper on your backend. Pass your permission-checking function to the constructor, and derive userId and callerAcl from the authenticated session.

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 alpha and recency_bias for fine-tuning
  • Metadata Filtering: Use source_title and source_type for 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

Conclusion

Building a Glean-like application with HydraDB APIs provides you with a scalable foundation for workplace search and AI assistance. By following this guide and implementing the best practices outlined, you can create a comprehensive solution that rivals commercial offerings while maintaining full control over your data and user experience. The key to success is starting with a solid architecture, implementing proper data synchronization, and gradually adding advanced features like multi-step reasoning, conversation memory, and personalized responses. HydraDB’s APIs provide the AI capabilities you need, while your application handles the data ingestion, user interface, and business logic. Remember to monitor performance, gather user feedback, and continuously iterate on your implementation to create the best possible user experience.

Change Log