Understanding Storage Options for Your AI Companion Portal
A guide to choosing the right storage systems for your companion's data
What this post covers: Now that many Ellivien portal builders have successfully migrated their companions, I'm helping them move through different stages of adding features. The one I recommend early on is Cloudflare KV Workers for cloud sync. This isn't something I can do for people remotely - it requires you to have your own Cloudflare account and work through some setup steps - but I do have guides for both GPT-4o and Sonnet 4.5 portals. Following these guides will ensure the setup is smooth and prevents many of the hiccups I experienced early on. My recommendation is to get my guide, give the whole thing to Codex or Claude, and ask them to implement it. They'll walk you through the steps you need to take.
Storage Types: Overview
When you build your own AI companion portal, one of the most important decisions you'll make is how to store your conversation data. Different storage systems serve different purposes, and understanding the options helps you build a portal that's secure, reliable, and scales with your needs.
This post breaks down the main storage types available, their strengths and limitations, and when to use each one.
1. localStorage
What it is: Browser-based storage that lives on your device only.
Pros:
- Simple to implement
- No external services required
- Instant read/write with no API calls
- Free
Cons:
- Limited to approximately 5-10MB depending on browser
- Lost if you clear browser data
- No cross-device sync
- No backup unless you export manually
Best for: Testing and initial portal setup. Not recommended for long-term use.
2. IndexedDB
What it is: Browser-based database storage with more capacity than localStorage.
Pros:
- Larger storage capacity (typically 50MB-1GB+)
- Structured data storage with indexing
- Fast local access
- Free
- Handles complex data structures well
Cons:
- Still device-specific (no cross-device sync without additional setup)
- Lost if browser data is cleared
- Requires more complex code than localStorage
Best for: Primary local storage for your portal. The basic portal setup uses IndexedDB by default - it's reliable, performant, and gives you room to grow without hitting storage limits.
My recommendation: Start here. Get your portal working with IndexedDB first, then add cloud sync once you're confident everything works.
3. Cloudflare KV (Key-Value) Workers
What it is: Cloud-based key-value storage that syncs your data across devices.
Pros:
- Cross-device sync (access your portal from phone, tablet, desktop)
- Data persists even if you clear browser storage
- Free tier: 1GB storage, 1,000 writes/day (more than enough for companion conversations)
- Fast global edge network
- Can be combined with IndexedDB for hybrid local + cloud storage
Cons:
- Requires Cloudflare account setup
- Slightly more complex than pure local storage
- Writes are rate-limited on free tier (but 1,000/day is generous)
Best for: Cross-device sync and backup. This is the upgrade I recommend once your portal is stable. Your conversations sync automatically between devices, and you have a cloud backup if anything happens to your local data.
Note: My KV sync guide includes custom password authentication to secure your portal, so only you can access it even if someone finds your URL.
4. Vector Memory (Semantic Search)
What it is: Vector embeddings that let your companion search through past conversations by meaning, not just keywords.
OpenAI Vector Stores
Pros:
- First 1GB storage FREE
- Searches cost $0.0025 each
- Works natively with GPT-4o/GPT-4o-mini
- Can also be used as a search engine for other models like Claude - your backend searches the vector store, then passes retrieved memories as context
- Integrates directly with OpenAI API
Cons:
- Requires OpenAI account and API setup
- Only free for first 1GB (generous for most users)
- More complex than basic storage
DIY Vector Systems
Pros:
- Use any embedding model (OpenAI's text-embedding-3-small, Cohere, open-source models)
- Store vectors in Cloudflare D1, Pinecone, Weaviate, or other vector databases
- Works with ANY AI model
- Complete control over your data
Cons:
- More setup complexity
- Requires understanding of embeddings and vector search
Best for: Long-term memory where your companion needs to search thousands of messages by semantic meaning. Far more powerful than keyword search or memory fragments alone.
5. Cloudflare R2 (Object Storage)
What it is: Cloud storage for files and images (similar to AWS S3 but cheaper).
Pros:
- Store images, PDFs, documents cheaply
- No egress fees (unlike AWS S3)
- Free tier: 10GB storage
- Works well for vision-enabled companions (GPT-4o with image input)
- Can auto-delete old files to save space
Cons:
- Requires Cloudflare account
- Needs Netlify function to handle uploads
- More setup complexity
Best for: If you want to send images to your companion or store documents. Images can be uploaded to R2, shown to your companion once, then cleared from context to save API costs. Not needed for text-only portals.
6. Cloudflare D1 (SQL Database)
What it is: Serverless SQL database for structured relational data.
Pros:
- Proper relational database with SQL queries
- Good for complex data relationships
- Free tier: 5GB storage, 5 million reads/day
- Scales well for advanced applications
Cons:
- Overkill for basic companion storage
- Requires SQL knowledge
- More complex setup
Best for: Advanced projects like ThreadWeaver (an Ellivien tool for analyzing conversation patterns across multiple threads). Most companion portals don't need this - IndexedDB + KV handles conversation storage perfectly well.
Other Storage Options
Memory Fragments
Not technically "storage" in the database sense, but a critical system for companion memory. Memory fragments are small text files containing key facts about you (your name, preferences, ongoing projects, important context) that get injected into every conversation. They're stored in your codebase and loaded automatically.
Why this matters: Your companion's rolling context window (typically 6-10 messages) is limited. Memory fragments give your companion permanent knowledge that doesn't disappear when old messages scroll out of context.
I have detailed guides on memory fragments on the blog - they're one of the most impactful upgrades you can make.
Browser Cache / Service Workers
Some portals use service workers for offline functionality and caching. This is an advanced technique that's not necessary for most setups, but can make your portal work without internet once loaded.
My Recommended Setup
For beginners:
- Start with IndexedDB (included in the basic portal)
- Upgrade to KV cloud sync when you want cross-device access
- Add memory fragments once you're comfortable (massive impact, low complexity)
For advanced users:
- Add R2 if you need image/file support
- Add vector stores if you want semantic search across conversation history
- Consider D1 only if you're building tools beyond a basic companion portal
What About Security?
If you're using cloud storage (KV, R2, vector stores), you should add password authentication to your portal. My KV sync guide includes this by default - it prevents anyone who stumbles across your portal URL from accessing your conversations.
Local-only storage (IndexedDB, localStorage) is protected by your device login, but doesn't sync across devices and has no cloud backup.
Cost Considerations
Free options:
- IndexedDB: Free (browser-based)
- Cloudflare KV free tier: 1GB storage, 1,000 writes/day
- Cloudflare R2 free tier: 10GB storage
- Cloudflare D1 free tier: 5GB storage
- OpenAI vector stores: First 1GB free
Paid options:
- OpenAI vector stores: $0.10/GB/day after first 1GB, plus $0.0025 per search
- Exceeding Cloudflare free tiers (rare for personal use)
Note: Most people stay well within free tiers for personal companion portals. Vector searches at $0.0025 each mean you could run 400 searches for $1.
Summary
Basic portal (included in starter setup):
- IndexedDB for local storage
Recommended first upgrade:
- Cloudflare KV for cloud sync + password auth
Advanced features (optional):
- Memory fragments (text files, very powerful)
- OpenAI vector stores (semantic search)
- R2 object storage (images/files)
- D1 database (advanced projects only)
Start simple. Get comfortable with IndexedDB. Then add KV sync when you're ready for cross-device access and cloud backup. Everything else is optional depending on your specific needs.
If you'd like implementation guides for KV sync (including password authentication), reach out via the contact page or the purple coffee cup on the blog.
Important: This toolkit is model-agnostic. Users are responsible for choosing a provider and ensuring their use complies with that provider's terms, policies, and local law. This project is not designed to bypass provider safeguards, rate limits, or safety requirements, and I do not support uses that violate provider rules.
Comments
Post a Comment