Queries and Documents
Task types.
A question and an answer don't look alike. Questions are short, and end in a question mark. Documents are longer statements. Some embedding models can embed each one in its own way, to match them better.

- Questions are short
- Documents are long
- Embed each their way
Two ways to embed
Embed documents is for chunks, and embed query is for questions. Behind the scenes, Gemini is told the task type, retrieval document, or retrieval query. Run it. The question scores higher against the battery sentence than the store hours.
import numpy as np
from langchain_google_genai import GoogleGenerativeAIEmbeddings
embeddings = GoogleGenerativeAIEmbeddings(model="gemini-embedding-001")
docs = ["The Volt 500 battery charges fully in about 4 hours.",
"York is open Monday to Saturday, 9am to 5:30pm."]
doc_vectors = np.array(embeddings.embed_documents(docs))
q = np.array(embeddings.embed_query("How many hours until my e-bike is full again?"))
scores = doc_vectors @ q / (np.linalg.norm(doc_vectors, axis=1) * np.linalg.norm(q))
for d, s in zip(docs, scores):
print(round(float(s), 2), d)0.73 The Volt 500 battery charges fully in about 4 hours. 0.59 York is open Monday to Saturday, 9am to 5:30pm.
The rule
Use embed documents when building the index, and embed query for every question. With LangChain's vector stores, this happens automatically. If you switch models later, re-embed everything, because vectors from different models can't be compared.
| key | value |
|---|---|
| Chunks | embed_documents |
| Questions | embed_query |
| Vector stores | do it for you |
| New model | re-embed all |
Summary
Embed chunks as documents, and questions as queries. Never mix vectors from different models. Next, vector stores.
Key takeaways- embed_documents
- embed_query
- One model per index