Prompt

How do I integrate embeddings into my app with an LLM API?

Artificial Intelligence / AI Platforms2 observationsLast seen Nov 1, 2026

Latest observation

Nov 1, 2026OpenAI APIWeb search: off

To integrate embeddings into an app that uses an LLM API, the usual pattern is:

  1. Create embeddings for your content
  2. Store them in a vector database or search index
  3. Embed the user’s query
  4. Retrieve the most similar items
  5. Pass the retrieved context to the LLM

This is the basis of semantic search and RAG (Retrieval-Augmented Generation).


1) What embeddings are used for

Embeddings turn text into vectors of numbers so you can compare meaning, not just keywords.

Typical uses:

  • semantic search
  • document retrieval
  • recommendations
  • clustering and deduplication
  • classification
  • RAG context selection

2) Basic architecture

Ingestion flow

  • Split documents into chunks
  • Generate embeddings for each chunk
  • Save:
    • chunk text
    • metadata
    • embedding vector

Query flow

  • User asks a question
  • Embed the question
  • Search for nearest vectors
  • Send top matches to the LLM as context
  • Generate answer

3) High-level implementation steps

Step A: Chunk your data

Don’t embed giant documents as one piece. Split into chunks, usually:

  • 200–800 tokens per chunk
  • some overlap between chunks

Example chunk metadata:

{
  "id": "doc_123_chunk_4",
  "text": "Refunds are available within 30 days...",
  "source": "help_center",
  "doc_id": "doc_123"
}

Step B: Generate embeddings

Call the embeddings endpoint from your LLM provider.

Example conceptually:

embedding = embed(text)

You’ll get a vector like:

[0.0123, -0.98, 0.44, ...]

Step C: Store vectors

Use a vector store such as:

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

Store:

  • vector
  • original text
  • metadata
  • ID

Step D: Query by similarity

At search time:

  • embed the user query
  • find nearest vectors using cosine similarity or dot product
  • return top-k results

Step E: Feed results to the LLM

Construct a prompt like:

  • system instructions
  • user question
  • retrieved context snippets

This helps the model answer using your data.


4) Simple example workflow

Indexing documents

docs = [
    "Our refund policy allows returns within 30 days.",
    "Shipping usually takes 3-5 business days.",
]

for doc in docs:
    vec = embed(doc)
    vector_db.upsert({
        "text": doc,
        "embedding": vec,
        "metadata": {"type": "help_article"}
    })

Answering a user question

query = "How long do I have to return something?"
query_vec = embed(query)

matches = vector_db.search(query_vec, top_k=3)

context = "\n".join([m["text"] for m in matches])

prompt = f"""
Use the context to answer the question.

Context:
{context}

Question:
{query}
"""

answer = llm.generate(prompt)

5) Recommended app pattern: RAG

If your app needs answers grounded in your own data, use RAG.

Why RAG?

  • keeps answers current
  • reduces hallucinations
  • works well with private/internal docs
  • avoids fine-tuning for simple knowledge retrieval

RAG pipeline

  1. ingest docs
  2. embed docs
  3. retrieve relevant chunks
  4. generate answer with retrieved context

6) Important design tips

Use chunking carefully

Bad chunking hurts retrieval. Aim for:

  • coherent sections
  • some overlap
  • keep chunks small enough for relevance, large enough for context

Store metadata

Useful metadata:

  • source
  • title
  • URL
  • timestamp
  • user/org access permissions

Filter before retrieval if needed

If your app has permissions, filter results by:

  • user ID
  • organization
  • document type
  • language

Re-rank for better quality

A common improvement:

  • retrieve top 20 by vector similarity
  • re-rank to top 5 with a smaller model or cross-encoder

Cache embeddings

If the same text is embedded often:

  • cache by hash
  • avoids repeated API calls

7) Choosing an embedding model

Pick an embedding model optimized for:

  • semantic similarity
  • your language coverage
  • cost and latency

General considerations:

  • lower-dimensional vectors are cheaper/faster
  • better models give higher retrieval quality
  • use the provider’s recommended embedding model for your use case

8) Common mistakes

  • Embedding entire books or huge pages as one chunk
  • Using keyword search only
  • Not storing metadata
  • Ignoring access control
  • Stuffing too much retrieved text into the prompt
  • Not evaluating retrieval quality
  • Assuming embeddings alone answer questions
    They only help retrieve relevant text; the LLM still generates the answer.

9) Minimal production checklist

  • chunk documents
  • embed and store vectors
  • build similarity search
  • add metadata filters
  • retrieve top-k chunks
  • pass context to LLM
  • log retrieval results
  • evaluate search quality
  • monitor cost/latency

10) If you want a practical stack

A simple, common stack:

  • LLM API for generation
  • Embedding API for vectors
  • Postgres + pgvector or Pinecone for storage/search
  • Your backend to orchestrate ingestion and query-time retrieval

If you want, I can also give you:

  1. a Python example using an embeddings API and pgvector,
  2. a JavaScript/TypeScript example, or
  3. a full RAG architecture diagram.

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.