Vector Search in Mobile AI Knowledge Base: pgvector, Embeddings, HNSW

In mobile development, a common problem arises: a user types a query like 'how to recover access' and the system returns a blank screen. Regular substring search fails with synonyms, typos, and different phrasings. **Vector search** solves this: it finds semantically similar documents, not exact mat

Development and support of all types of mobile applications:

Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1All 1734 services
Vector Search in Mobile AI Knowledge Base: pgvector, Embeddings, HNSW
Complex
~5 days

Our competencies:

Frequently Asked Questions

Latest works

  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    896
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    782
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1216
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    1079
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    1003
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    597

In mobile development, a common problem arises: a user types a query like 'how to recover access' and the system returns a blank screen. Regular substring search fails with synonyms, typos, and different phrasings. Vector search solves this: it finds semantically similar documents, not exact matches. 'recover access' → 'reset password' → the needed article is found in milliseconds. Over 5 years, we have implemented such search in 20+ iOS and Android projects, and now we share practical experience.

According to pgvector documentation, semantic search can be implemented using HNSW and IVFFlat indexes, providing high speed even on millions of vectors.

How vector search works at the code level

Each text fragment is converted into a vector — an array of numbers with dimension 384, 768, or 1536 (depending on the model). Semantically similar texts have close vectors. Search means finding the nearest vectors to the query (Approximate Nearest Neighbor, ANN).

In practice, the pipeline looks like this:

  1. The user enters a query in the mobile app.
  2. The client sends the query to the backend.
  3. The backend generates an embedding via API (OpenAI, Cohere) or a local model.
  4. The vector DB returns the top-K nearest chunks.
  5. The results are passed to an LLM for summarization or returned directly.

The entire pipeline up to step 4 takes 50–300 ms — quite acceptable for mobile UX. For comparison, pgvector on average returns results in 100 ms, which is 3 times faster than Pinecone with the same HNSW index on a set of 500,000 documents.

Why pgvector is better for mobile projects

pgvector is a PostgreSQL extension that adds support for vector indexes. If you already have PostgreSQL, that's zero additional infrastructure. We use it in 80% of projects where the document volume does not exceed 1 million. The table below compares popular solutions:

Parameter pgvector Pinecone Qdrant
Latency (p50) 50–150 ms 20–50 ms 30–80 ms
Maximum volume 10M+ (more complex) 100M+ 100M+
Cost per 1M vectors $0 (included in Postgres) ~$70/month $25/month (self-host)
Metadata filtering ✅ (after ANN) ✅ (configurable) ✅ (configurable)
Offline mode

pgvector supports HNSW and IVFFlat indexes. HNSW provides better accuracy and search speed but requires more memory during construction. For knowledge bases up to 500,000 documents, HNSW works well out of the box.

-- Create HNSW index for cosine distance CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64); -- Search top-5 nearest SELECT id, content, 1 - (embedding <=> $1) AS similarity FROM documents ORDER BY embedding <=> $1 LIMIT 5; 

<=> is cosine distance. For normalized vectors, you can use inner product (<#>), but <=> works without normalization.

How to generate embeddings on a mobile device?

There are two approaches: server-side and client-side. Server-side is preferable for most applications — embedding models weigh 80–500 MB, local inference drains battery, and API keys are not exposed from the APK. The exception is a fully offline scenario, such as a corporate app for working without internet. On iOS we use Core ML (conversion via coremltools), on Android — ONNX Runtime. Example: all-MiniLM-L6-v2 in ONNX weighs ~22 MB and produces 384-dimensional vectors sufficient for documentation search.

Below is a comparison of popular embedding models for mobile use:

Model Dimension Disk size Quality (MTEB)
all-MiniLM-L6-v2 384 22 MB 56.3
BGE-small-en 384 33 MB 58.9
intfloat/e5-base-v2 768 113 MB 61.3
How to tune HNSW index parameters? The `ef_search` parameter controls the number of nodes examined during search: higher gives better accuracy but slower speed. `ef_construction` affects index build quality. Recommended values: ef_search = 40–100 for balance, ef_construction = 200–400 for large datasets.

Metadata filtering — pitfalls

Vector search without filters searches the entire index. If you need to limit the search scope (e.g., only documents for product X in Russian), add filters:

SELECT id, content, 1 - (embedding <=> $1) AS similarity FROM documents WHERE language = 'en' AND category = 'installation' AND updated_at > NOW() - INTERVAL '1 year' ORDER BY embedding <=> $1 LIMIT 10; 

Important: pgvector performs filtering after vector search when using HNSW/IVFFlat. For highly selective filters (selecting < 10% rows), this can lead to empty results — you need to build separate indexes for each subset or use partitioned HNSW, which we configure as needed.

What is included in the implementation

  • Audit of the existing knowledge base: structure, volume, content types.
  • Selection of embedding model and dimension (384/768/1536) for your scenario.
  • pgvector setup: index creation, optimization of ef_search and ef_construction.
  • Development of ingestion pipeline — automatic chunking and vectorization of documents.
  • Search API with support for filtering, pagination, and sorting.
  • Mobile UI integration (search bar, results, breadcrumbs).
  • Quality testing: precision@K, recall@K, A/B tests.
  • Optimization for offline mode if needed.
  • Documentation and source code handover.

Timeline and how to start

Vector search for a corpus of up to 50,000 documents with pgvector — 2–4 weeks. With a custom embedding model, reranking, and multilingual support — 5–8 weeks. The cost is calculated individually after analyzing your knowledge base.

Our engineers are certified in iOS and Android, guaranteeing result quality. Get an express project estimate in 2 days — contact us for a consultation. Order a detailed audit of your current knowledge base to identify bottlenecks.