Prompt

How do I use embeddings for semantic search in a document app?

Artificial Intelligence / AI Search2 observationsLast seen Nov 22, 2026

Latest observation

Nov 22, 2026OpenAI APIWeb search: off

To use embeddings for semantic search in a document app, the basic idea is:

  1. Break documents into chunks
  2. Convert each chunk into an embedding vector
  3. Store those vectors in a vector database or index
  4. Embed the user’s search query
  5. Find the most similar chunks by vector similarity
  6. Return the matching documents/chunks

1) Chunk your documents

Don’t embed an entire long document as one vector. Split it into smaller pieces like:

  • paragraphs
  • sections
  • 200–500 token chunks with overlap

Why:

  • better retrieval precision
  • easier to return the exact relevant passage
  • reduces token limits and improves search quality

Example:

  • Document A → 12 chunks
  • Document B → 8 chunks

Store metadata with each chunk:

  • document ID
  • title
  • section heading
  • page number
  • chunk text
  • chunk order

2) Generate embeddings

Use an embedding model to turn each chunk into a numeric vector.

Example conceptually:

  • "How do I reset my password?" → [0.12, -0.44, ...]
  • "Password reset steps..." → another vector

Similar meanings end up near each other in vector space.

3) Store vectors in a searchable index

Use a vector database or vector search layer such as:

  • Pinecone
  • Weaviate
  • Milvus
  • pgvector (Postgres)
  • Elasticsearch / OpenSearch vector search
  • FAISS

Each stored record usually contains:

  • chunk_id
  • embedding
  • text
  • metadata

4) Search flow

When the user types a query:

  1. Embed the query
  2. Compare it with stored chunk embeddings
  3. Retrieve the top-k most similar chunks

Similarity metrics:

  • cosine similarity
  • dot product
  • Euclidean distance

Usually cosine similarity is a common choice.

5) Return results

You can return:

  • the best-matching chunk text
  • the parent document title
  • highlight the relevant sentence
  • open the doc at the relevant section

Optional: rerank the top results using a more expensive model for better precision.


Simple architecture

Indexing time

  • ingest docs
  • chunk them
  • embed chunks
  • save vectors + metadata

Query time

  • embed query
  • vector search top-k
  • optionally rerank
  • show results

Pseudocode example

# indexing
for doc in documents:
    chunks = split_into_chunks(doc.text)
    for chunk in chunks:
        vec = embed(chunk)
        vector_db.upsert({
            "id": chunk.id,
            "vector": vec,
            "metadata": {
                "doc_id": doc.id,
                "title": doc.title,
                "text": chunk.text
            }
        })

# searching
query_vec = embed(user_query)
results = vector_db.search(query_vec, top_k=5)

for r in results:
    print(r.metadata["title"], r.metadata["text"])

Practical tips

Chunking

  • Use overlap between chunks so context isn’t lost
  • Don’t make chunks too large
  • Keep chunks semantically coherent

Metadata

Store enough metadata so you can:

  • filter by document type, author, date, permissions
  • trace results back to the original document

Hybrid search

Best results often come from combining:

  • keyword search (BM25)
  • semantic search (embeddings)

This helps when the query includes:

  • exact names
  • IDs
  • technical terms
  • rare keywords

Permissions

If your app has access control, filter search results by user permissions before returning them.

Re-ranking

Semantic search gets candidates; reranking improves quality. A common pattern:

  • retrieve top 20 by vector similarity
  • rerank top 20 with a cross-encoder / LLM
  • show top 5

When embeddings work well

Great for:

  • “find docs about onboarding”
  • “show me pages that discuss scaling issues”
  • “where is the policy about remote work?”

Less ideal alone for:

  • exact string matches
  • IDs, codes, filenames
  • highly structured queries

That’s why hybrid search is often best.

If you want, I can also give you:

  1. a Python example using pgvector or Pinecone, or
  2. a full end-to-end design for a document search app.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.