AlloyDB AI solves PostgreSQL's CJK full-text search problem
Key Takeaways
Master Postgres Full-text Search in 5 Minutes
- PostgreSQL's standard tokenization fails for Chinese, Japanese, and Korean because these languages lack whitespace between words
- AlloyDB AI's ai.generate() function calls Gemini directly from SQL, enabling intelligent word segmentation without external ETL pipelines
- The approach eliminates data movement, keeps preprocessing inside the database, and handles semantic ambiguity that dictionary-based tools miss
Google Cloud has detailed how AlloyDB AI solves a longstanding PostgreSQL limitation: full-text search for Chinese, Japanese, and Korean. The solution uses Gemini directly inside SQL queries to tokenize logographical text, bypassing the external preprocessing pipelines that have historically plagued teams working with CJK languages.
Why PostgreSQL full-text search breaks on CJK languages
PostgreSQL's to_tsvector function splits text into searchable tokens by looking for whitespace. English, German, French, Spanish, most Latin-script languages, all play nicely with this model. Chinese does not. Japanese does not. Korean often does not.
Consider the Chinese sentence: "你们研究所有十个图书馆" (Your research institute has ten libraries). Without spaces, PostgreSQL treats the entire string as a single lexeme. Search for "研究所" (research institute) or "图书馆" (library), and you get zero results. The keywords exist in the string, but they're trapped inside an unbroken character sequence.
This isn't a minor edge case. Over 1.5 billion people speak Chinese, Japanese, or Korean as a first language. Any application targeting these markets, e-commerce, content platforms, enterprise search, hits this wall the moment it needs full-text indexing.
The workarounds everyone has tried
Three approaches dominate current practice. None of them work well.
- Database extensions like zhparser or pg_jieba add Chinese tokenization to PostgreSQL, but managed database services rarely support them. They also rely on static dictionaries that choke on modern slang, brand names, and context-dependent terms.
- External preprocessing pipelines export text to Python microservices running jieba or spaCy, insert spaces, then write the modified text back. This adds ETL complexity, network latency, and moves sensitive data outside the database tier.
- Dictionary-driven segmentation can't resolve semantic ambiguity. The same character sequence often requires different segmentation depending on meaning. Static rules don't have the context to make the right call.
The fundamental problem: accurate segmentation requires world knowledge. A dictionary knows words. A language model understands which words make sense in context.
How AlloyDB AI's ai.generate() changes the approach
AlloyDB AI introduces native AI functions that call Gemini directly from SQL. The ai.generate() function lets you pass text to Gemini, get back intelligently segmented tokens, and use those tokens for indexing, all without leaving the database.
Google highlights three architectural advantages:
- No data movement. Text preprocessing happens inside the database engine. No network round-trips to external services, no data exposure outside your database boundaries.
- No microservice maintenance. You don't build, deploy, or babysit a Python tokenization service. The database coordinates model calls natively.
- Batched execution via stored procedures. PL/pgSQL procedures with array aggregation process rows in parallel batches, commit each batch immediately, and avoid memory exhaustion or row lock contention.
The practical result: you write a SQL query that calls ai.generate() with your Chinese text, Gemini returns space-separated tokens, and PostgreSQL's standard full-text search takes over from there.
What about RUM indexes?
Google also announced RUM index support in AlloyDB, which enhances full-text search performance beyond PostgreSQL's standard GIN indexes. RUM indexes store positional information, enabling faster phrase searches and ranking queries. Combined with AI-powered tokenization, this gives AlloyDB a full stack for multilingual search: intelligent parsing via Gemini, efficient indexing via RUM, and ranked results via SQL.
Where this matters most
E-commerce platforms with Asian market exposure benefit immediately. Product catalogs, customer reviews, support tickets, anything searchable in CJK languages becomes properly indexable. Content management systems and knowledge bases face the same problem at smaller scale.
The approach also has implications for hybrid search architectures combining full-text and vector search. AlloyDB already supports vector indexes for semantic similarity. Adding accurate CJK tokenization closes a gap that forced teams to route different languages through different search paths.
Logicity's Take
AlloyDB's approach trades one dependency for another. You eliminate external preprocessing services but take on a runtime dependency on Gemini API calls. For high-throughput workloads, watch latency and cost carefully, Gemini calls aren't free. Elasticsearch with CJK analyzers or Typesense with built-in tokenization remain alternatives if you want search infrastructure decoupled from your primary database. That said, for teams already committed to AlloyDB, this is the cleanest path to CJK search we've seen.
Frequently Asked Questions
Does AlloyDB AI support languages other than Chinese, Japanese, and Korean?
The ai.generate() function works with any language Gemini supports. The CJK use case is highlighted because those languages specifically break PostgreSQL's whitespace-based tokenization.
Can I use AlloyDB AI functions with existing PostgreSQL extensions?
AlloyDB is PostgreSQL-compatible, so standard extensions work. However, the AI functions are AlloyDB-specific and won't run on vanilla PostgreSQL or other managed Postgres services.
What's the latency impact of calling Gemini for tokenization?
Google recommends batched execution via stored procedures to amortize API call overhead. For write-heavy workloads, consider preprocessing at insert time rather than query time.
How does this compare to using Elasticsearch for multilingual search?
Elasticsearch has mature CJK analyzers built in. AlloyDB's advantage is keeping search logic inside your primary database, eliminating synchronization between separate data stores.
Related Google Cloud AI governance approach for enterprise deployments
Need Help Implementing This?
Setting up AlloyDB AI functions for multilingual search requires careful batching and index strategy. If your team needs guidance on migration from PostgreSQL or architecture review for CJK search workloads, reach out to Logicity's consulting network.
Source: Cloud Blog
Manaal Khan
Tech & Innovation Writer
Produced with AI assistance and reviewed by the Logicity editorial team. Learn more in our Editorial Policy.






