Embeddings
Turn any text into dense vectors. Useful for semantic search, similarity comparison, clustering, and RAG retrieval augmentation.
Endpoint
httpPOST https://api.aicodedog.com/v1/embeddings
Popular models: text-embedding-3-large (3072 dim, top quality), text-embedding-3-small (1536 dim, best value), bge-m3 (strong on both Chinese and English).
Minimal request
curlcurl https://api.aicodedog.com/v1/embeddings \ -H "Authorization: Bearer $AICODEDOG_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "text-embedding-3-small", "input": "An API relay lets you call many models with a single key" }'
pythonfrom openai import OpenAI client = OpenAI(api_key="<KEY>", base_url="https://api.aicodedog.com/v1") resp = client.embeddings.create( model="text-embedding-3-small", input=["first paragraph", "second paragraph", "third paragraph"], # batches also work ) vectors = [d.embedding for d in resp.data] print(len(vectors[0])) # 1536
Parameters
model(required) — model slug.input(required) — a string or an array of strings. Batches up to 2048 items per request are most efficient.dimensions— truncation length (v3 series only). Setting512drops 1536-dim vectors to 512 dims, storage cost goes down to 1/3.encoding_format—float(default) orbase64(saves bandwidth).
Cosine similarity
Once you have two vectors, cosine similarity is the standard "how close are they?" metric:
pythonimport numpy as np def cosine(a, b): a, b = np.array(a), np.array(b) return float(a @ b / (np.linalg.norm(a) * np.linalg.norm(b))) # 1.0 = identical; 0.0 = unrelated; -1.0 = opposite print(cosine(vectors[0], vectors[1]))
Typical use: RAG retrieval
1. Chunk every document, embed each chunk, store the vectors in a vector DB (Pinecone / Weaviate / pgvector / Qdrant).
2. When a user asks a question, embed the question too and pull the top-k most similar chunks from the DB.
3. Splice those chunks into the system prompt and let chat completions answer based on "the retrieved material".
That's what people call RAG — Retrieval Augmented Generation.