Start llama-server in embedding mode with a compatible GGUF embedding model and a pooled output. Call the models route to confirm the HTTP connection, then send two short strings to the embeddings route and check that each input has its own vector. Record the model and settings before indexing any real text. Two different encoders can produce vectors of the same length, so a dimension check alone cannot establish that an old index matches a new deployment.
This example uses the llama.cpp project’s GGUF conversion of BGE Small English v1.5. You can repeat the procedure with another compatible embedding model if you update the pooling and dimension expectations from its documentation. The input is limited to fictional notes about a workshop. The goal is to demonstrate the API contract and preserve the information needed to reproduce it.
Select the embedding artifact and its pooling
Download the GGUF file from the runtime project’s model repository. Its model name includes BGE Small English v1.5 and its quantization. Check the full filename before starting the service, especially if your Mac has another BGE version or conversion. The original model publisher describes 384-dimensional embeddings and demonstrates selecting the first token representation followed by normalization. This example makes the pooling choice explicit as CLS. GGUF conversion from the llama.cpp project, original BGE model card.
A model produces representations for input tokens. Pooling determines how the implementation obtains a single vector for a whole input. The server offers several pooling modes. Use the one specified for the chosen artifact. An arbitrary pooling change can produce output of the expected size while changing the coordinates that a similarity search uses. For a different architecture or model, check its documented behavior before copying this command.
Decide whether you want to start a separate listener for the experiment. A chat client may already be using a llama.cpp listener on the same Mac. This walkthrough uses port 8081 and loopback, so it can coexist with a client that points to another port. Confirm you have the llama-server executable available and that its help lists embedding options. This also checks which binary your shell will use if more than one installation exists.
Start the dedicated listener
Replace the file path with the downloaded model’s exact path. The example gives the service a recognizable API name through its alias argument. Keep the host on loopback for callers on the same Mac. Leave this Terminal open while you send test requests from another one.
llama-server -m '/absolute/path/to/bge-small-en-v1.5-q8_0.gguf' \
--embedding --pooling cls --alias workshop-embeddings \
--host 127.0.0.1 --port 8081
Check the startup output for the model file and listen address. If loading stops with an architecture or file error, fix the artifact or runtime compatibility before changing a client. For the first request, check health and then the API’s model listing on the chosen port. The route documentation distinguishes the OpenAI-compatible embeddings response from the server’s native route. This example uses the former and asks for floating-point outputs. llama.cpp server options and embeddings API.
curl -sS http://127.0.0.1:8081/health
curl -sS http://127.0.0.1:8081/v1/models
The listing should give you an ID for this setup. Use the exact returned identifier in the next request. If your server shows a different value, inspect the startup command and the model list, then change the request to match. A successful HTTP response from the model listing gives you evidence about the listener. The embeddings test will establish which kind of computation it actually returns.
Request vectors for two short notes
These two texts refer to different items. The expected property is one numeric vector per input, associated with its original position. There is no expected numeric value for an individual coordinate. Save the response under a new filename in a test directory so the existing contents of a real index remain out of the exercise.
curl -sS -w 'HTTP %{http_code}\n' \
http://127.0.0.1:8081/v1/embeddings \
-H 'Content-Type: application/json' \
-o workshop-embeddings.json \
-d '{
"model":"workshop-embeddings",
"encoding_format":"float",
"input":[
"The soldering station has a brass tip cleaner.",
"The overhead projector uses a spare violet lamp."
]
}'
Begin by looking at the status. When a server error arrives, read the saved body before trying a second input. A request to the chat listener may give you a response on a similar URL but have a completely different backend purpose. If the example returns the normal data, parse it as JSON. Each row should have an index and a list of floating-point coordinates. Zero is a reasonable value for an individual coordinate. A vector made entirely of zero would be unsuitable for this example.
Save this checker as check-embeddings.py beside the saved response. Run it with Python 3. It checks count, order labels, size, and numerical validity without treating a specific value as universal across builds.
import json
import math
with open("workshop-embeddings.json", encoding="utf-8") as file:
body = json.load(file)
rows = sorted(body["data"], key=lambda row: row["index"])
if [row["index"] for row in rows] != [0, 1]:
raise ValueError("Expected one row each for indices 0 and 1")
for row in rows:
vector = row["embedding"]
if not isinstance(vector, list) or len(vector) != 384:
raise ValueError(f"Unexpected vector size for index {row['index']}")
if not all(type(value) in (int, float) and math.isfinite(value) for value in vector):
raise ValueError(f"Non-finite or non-numeric output for index {row['index']}")
if not any(value != 0 for value in vector):
raise ValueError(f"Zero vector for index {row['index']}")
if rows[0]["embedding"] == rows[1]["embedding"]:
raise ValueError("The two different notes returned identical vectors")
print("Two distinct, finite vectors of 384 dimensions.")
The last check makes it easier to catch a fixture that accidentally sent the first note twice, or a simple implementation error that reused a vector. It is a sanity check for these two inputs. It does not rank their similarity or set a general quality threshold. In a production consumer, retain the index labels explicitly because array position and the original input position are different pieces of information.
Check a changed request without a database
Reverse the note order and save the second response under a new name. Each row should still carry an index associated with its own request. This is a practical test for code that plans to associate output vectors with filenames or record IDs. For example, you can label the initial payload’s first string soldering and its second string projector in a small local manifest. When you reverse the payload, reverse the labels too. The labels will later let you inspect search results without reconstructing how the API response was attached.
Then try the projector note by itself. There should be a single row with index zero and the same dimension. Adjust the expected count in a temporary copy of the checker. Seeing a row with index zero in two different requests does not imply that the first text in each request was the same. Use the manifest’s document identity to connect a vector to its original text across requests.
If the response arrives with a base64 string or a different array structure, verify the encoding setting and request route. The non-compatibility route has a different response shape. If the server responds with an error about pooling, confirm that its actual process was started with a suitable model and pooling mode. If startup has a model fit or context message, keep the first inputs short to isolate the issue before you divide a real collection of documents into chunks.
Make an index reproducible before adding files
Write down the model repository, exact GGUF filename, revision or checksum you used, server build, pooling, dimension, and any text preprocessing you intended. The model card distinguishes document and query phrasing in its retrieval examples. For a real query-and-document test, follow the model’s guidance and record that formatting separately from the service’s transport. A change in the prefix can alter the representation even though the API takes the same kind of string.
When investigating retrieval failures, begin with a tiny local collection whose expected matches you can describe. A query about a replacement lamp should have a more meaningful candidate in the projector note than in an unrelated soldering note. Add a plausible distractor, such as a desk lamp entry, to learn whether the query wording captures the distinction you need. That is a relevance exercise. The API shape check here precedes it and is easier to repeat after a server change.
Keep a prior index separate when changing an embedding artifact, pooling choice, or text preprocessing rule. Equal vector lengths make it technically possible for software to combine two groups of coordinates without noticing the change. A small retrieval collection and a saved configuration give you a way to verify the new group before exchanging it with the old one. After the practice requests, stop the foreground server with Control-C when the listener is no longer needed, or leave it running intentionally for the local caller you identified.
Preserve the link between vectors and their sources
Keep the original note labels when you save vectors for later analysis. In this exercise, the soldering label and projector label name source notes, while index zero and index one refer to positions in one particular batch. In a real tool, write down the file identity and the paragraph or chunk identity before the request. Once a response arrives, join each row to its input through the row index. Avoid inferring the association from a vector value or from the order you see in a pretty-printed viewer.
One way to practice with the fixture is to create a third note about replacement ear cushions, issue a two-item request with only the projector and cushions, and save its response separately. The same label may now belong to a different index depending on how you composed the input. Check the labels against the request body before writing any simulated index entry. The service returns numeric rows and positional information. The caller is responsible for the identity of the source behind each row.
If you later change which lines are present in a note, keep that change visible in the manifest. An embedding represents the text the service received, including your choice to remove a header or put several sentences together. Two versions of the same document can therefore produce different vectors without any server change. Recording the input text or a version identifier during the small practice run gives you a clear source to revisit when a future result seems out of place. That discipline helps local search remain auditable after you move past the two-note exercise.
Validate a consumer’s count and dimension checks
Use a stored practice response to test the software that reads vectors. First, run the checker on the unchanged two-note response. Then copy the JSON and remove a coordinate from the first row. The check should identify the wrong dimension. In a second copy, replace the index of one row with the other row’s index. This represents a consumer that would attach two vectors to the same input. The position check should fail even though both vectors still have valid lengths.
Use these altered fixtures locally. Creating them by editing a saved file makes the checks repeatable without expecting the running service to produce invalid data. If your consumer imports the batch into a database, validate all rows and their association before adding them. A report that says one row failed gives you an opportunity to retry the complete batch from its known strings. Silently inserting valid rows from an otherwise rejected response can make a retry create duplicates or gaps, depending on the consumer’s database rules.
When you change the selected model later, update the expected dimension from its own file record. Keep the earlier output with its configuration. If the new model has the same size, a simple response check can still pass for both models. Use the explicit model artifact record and a separate test index to distinguish which one produced the vectors you intend to keep.