Embeddings
SynergyDB has two embedding subsystems that share no code and no configuration:
| Subsystem | Code | Used by | Configured with | Offline default |
|---|---|---|---|---|
| Vector service embedders | src/vector/embed.rs |
Cross-wire vector collections, SQL embed(), text queries on every wire's vector search |
Per collection, or SYNERGYDB_EMBED_URL, SYNERGYDB_EMBED_MODEL, SYNERGYDB_EMBED_API_KEY
|
Lexical hash embedder, 384 dimensions |
| HTTP embedding providers | src/protocol/http/embeddings.rs |
POST /v1/embeddings, document ingest with auto_embed, LangChain retrieve |
OPENAI_* or HUGGINGFACE_* variables |
Mock provider, 1536 dimensions |
(source: src/vector/embed.rs, EmbedderSpec::default_for; src/protocol/http/embeddings.rs, EmbeddingProvider::from_env, generate_mock_embeddings)
How collections store vectors, build their HNSW graph and search is on HNSW, pgvector and the vector service. This page covers where vectors come from. The operator view is in How it works.
Vector service embedders (src/vector/embed.rs)
EmbedderSpec
The embedder is part of a collection's definition. It is serialized as JSON tagged by provider in snake_case:
provider |
Fields | Meaning |
|---|---|---|
hash |
dims |
Built-in lexical feature hashing, no network |
openai |
url, model, dims, api_key_env (all optional) |
Any server that speaks the OpenAI /embeddings API |
(source: src/vector/embed.rs, EmbedderSpec)
api_key_env names an environment variable; the key itself is read at call time and is never written into the collection definition. (source: src/vector/embed.rs, EmbedderSpec::embed; src/vector/sources.rs, CrossWireOptions)
Choosing the default
When a collection is created without an embedder, default_for(dims) picks one:
-
SYNERGYDB_EMBED_URLset and non-empty:openaiwith no fields set, so URL, model and key come from the environment at call time. - Otherwise:
hashwith the declared dimensions, or 384 if none were declared.
(source: src/vector/embed.rs, EmbedderSpec::default_for)
A default embedder is only attached when the collection has text sources or declares no dimensions. A collection fed only by vector fields with declared dims gets no embedder and can only be searched with a vector. (source: src/vector/sources.rs, create_collection)
The hash embedder
hash_embed(text, dims) produces a deterministic, L2-normalized vector:
- Lowercase the text and split on non-alphanumeric characters.
-
light_stemeach word: striping,es,ed,lyorswhen the word is longer than the suffix plus two characters; after strippinging, also undouble a final double consonant (runningbecomesrun). - For each stem add the feature
w:{stem}with weight 1.0, and each trigram of^stem$asg:{trigram}with weight 0.25. - Hash each feature with 64-bit FNV-1a. Bucket =
hash % dims; sign = bit 63 of the hash. - Normalize to unit length.
dimsis raised to at least 1.
(source: src/vector/embed.rs, hash_embed, light_stem, fnv1a)
The result captures shared words and spelling, not meaning. Tested by hash_embedder_is_deterministic_and_lexical. (source: src/vector/tests.rs, that test)
The openai embedder
EmbedderSpec::embed resolves its settings in this order:
| Setting | Spec field | Environment fallback | Default |
|---|---|---|---|
| Base URL | url |
SYNERGYDB_EMBED_URL |
None: error embedding endpoint not configured
|
| Model | model |
SYNERGYDB_EMBED_MODEL |
nomic-embed-text |
| API key | env var named by api_key_env
|
SYNERGYDB_EMBED_API_KEY |
No Authorization header |
(source: src/vector/embed.rs, EmbedderSpec::embed, non_empty)
The request is POST {url}/embeddings with body {"model": ..., "input": [texts]} and a bearer token if a key was found. It runs on a dedicated thread with a current-thread Tokio runtime and a 120 second timeout, so it can be called from synchronous engine code. (source: src/vector/embed.rs, http_embed)
| Failure | Error |
|---|---|
| Non-2xx status | Status plus up to 300 characters of the body |
Response without a data array |
no data array |
| Number of vectors differs from number of inputs | Count mismatch |
Vector length differs from a non-zero dims
|
Error::VectorDimensionMismatch |
Results are reordered by each item's index field. An empty input list returns an empty result without a request. (source: src/vector/embed.rs, embed, http_embed)
The HTTP client exists only when the rest-api Cargo feature is on (it is in the default feature set). Without it, http_embed returns this build has no HTTP client (feature rest-api); use the hash embedder. (source: src/vector/embed.rs, http_embed stub; Cargo.toml, [features])
Not verified: no test in the snapshot calls a real or stubbed OpenAI-compatible server through this path. The 2026-11-24 status entry reports a cross-wire end-to-end script at 10/10, but that script (test-scripts/crosswire-vector) is not in the snapshot. (source: docs/status/2026-11-24-cross-wire-vector-search.md)
Dimensions
| Case | Result |
|---|---|
dims declared and embedder given |
Must match, else dims {n} does not match the embedder's {m}
|
openai embedder with dims 0 or absent |
The service embeds the text dimension probe once at creation and stores the returned length |
No dims, no embedder, no text sources |
give "dims" (or an embedder) for the collection |
IF NOT EXISTS on an existing collection |
Returns it unchanged; no probe |
(source: src/vector/sources.rs, create_collection)
From source record to vector
The background indexer turns each source row, document or hash into a record:
-
Text fields are joined with a newline. Arrays are flattened, nulls skipped, and non-string scalars converted with
to_string. Text that is empty or only whitespace produces no vector. (source:src/vector/sources.rs,make_record) -
Vector fields accept a JSON array, pgvector text (
[1,2,3]) or{"$vector": [...]}. A Redis hash field may hold raw little-endianf32bytes of exactlydims * 4bytes, or text. (source:src/vector/sources.rs,json_vector,redis_vector) - A vector of the wrong length or with a non-finite element turns the record into a delete. (source:
src/vector/sources.rs, indexer) -
Change detection uses
content_hash: Rust'sDefaultHasherover the text, the vector's bit patterns and the payload JSON, printed as 16 hex digits and stored as_h. A record whose hash is unchanged is not re-embedded. (source:src/vector/sources.rs,content_hash) - Batching: texts are embedded 64 per call; batching thresholds and upsert cadence are on the vector service page.
A collection with text sources but no embedder fails indexing with collection ... has text sources but no embedder. (source: src/vector/sources.rs, indexer)
Text queries
embed_query(def, text) embeds a query with the collection's own embedder, so query and stored vectors come from the same model. A collection without an embedder returns vector collection "{name}" has no embedder; search it with a vector. (source: src/vector/sources.rs, embed_query)
| Wire | How a text query is recognized |
|---|---|
SQL vector_search(collection, query, k)
|
query not starting with [ is text |
SQL embed(text [, collection])
|
With a collection: that collection's embedder. Without: default_for(None). NULL text returns NULL |
Redis FT.SEARCH ... KNN
|
A $param blob whose length is not dims * 4 is treated as UTF-8 text |
MongoDB $vectorSearch
|
query.text, or query given as a string |
Elasticsearch knn
|
query_vector_builder.text_embedding.model_text |
Neo4j db.index.vector.queryNodes
|
A string instead of a list as the query |
(source: src/vector/sources.rs, sql_call, sql_search; src/protocol/redis/commands/search.rs, KNN parameter handling; src/protocol/mongodb/vector_search.rs; src/protocol/elasticsearch/crosswire.rs; src/protocol/bolt/vector_index.rs, crosswire_query)
HTTP embedding providers (src/protocol/http/embeddings.rs)
Provider selection
EmbeddingProvider::from_env runs once and the result is kept in a process-wide OnceLock (get_embedding_provider; tests replace it with set_embedding_provider):
| Condition | Provider | Model variable and default | Endpoint |
|---|---|---|---|
OPENAI_API_KEY set |
OpenAI |
OPENAI_EMBEDDING_MODEL, text-embedding-3-small
|
OPENAI_BASE_URL (default the public OpenAI API) + /v1/embeddings
|
Else HUGGINGFACE_API_KEY set |
HuggingFace |
HUGGINGFACE_MODEL, sentence-transformers/all-MiniLM-L6-v2
|
HuggingFace Inference feature-extraction pipeline for that model, with wait_for_model: true
|
| Else | Mock |
n/a | None; a warning is logged |
(source: src/protocol/http/embeddings.rs, from_env, get_embedding_provider)
A fourth variant, Local { model_path }, returns Unsupported ("not yet implemented"). Not wired: nothing selects it. (source: src/protocol/http/embeddings.rs, EmbeddingProvider::Local)
OpenAI requests send encoding_format: "float" and pass dimensions through. A response missing an item yields InvalidResponse ("Missing embedding for index"). Error variants are HttpError, ApiError, InvalidResponse and Unsupported. (source: src/protocol/http/embeddings.rs, generate_openai_embeddings, EmbeddingError)
The Mock provider fills each dimension from DefaultHasher over (text, i), maps it into [-1, 1] and normalizes. Default length 1536. (source: src/protocol/http/embeddings.rs, generate_mock_embeddings)
POST /v1/embeddings
| Request field | Handling |
|---|---|
input |
A string, an array of strings, or arrays of token ids. Token ids are joined as decimal numbers with spaces and embedded as that text; they are not decoded |
model |
Default text-embedding-3-small; echoed back in the response, whatever provider ran |
encoding_format |
Default float; base64 returns little-endian f32 bytes in base64 |
dimensions |
Passed to the provider |
user |
Ignored |
(source: src/protocol/http/routes.rs, openai_embeddings; src/protocol/http/models.rs, OpenAIEmbeddingsRequest)
usage.prompt_tokens is an estimate: byte length divided by 4, at least 1 per input. (source: src/protocol/http/routes.rs, openai_embeddings)
If the provider returns an error, generate_embeddings logs it and answers with mock vectors instead of an error status. A client cannot tell from the response that this happened. (source: src/protocol/http/routes.rs, generate_embeddings)
GET /v1/models returns a fixed list of three model ids owned by synergydb, independent of the provider. The same generate_embeddings function serves /api/v1/documents/ingest with auto_embed and /api/v1/langchain/retrieve. (source: src/protocol/http/routes.rs, openai_list_models, document ingest and LangChain handlers)
Tests
tests/embeddings_test.rs is compiled only with the rest-api feature:
| Test | Needs network | Checks |
|---|---|---|
test_mock_provider, test_mock_provider_different_dimensions, test_mock_provider_consistency
|
No | Length, normalization, determinism |
test_empty_text_list, test_large_batch
|
No | Edge cases on the mock |
test_provider_from_env |
No | Selection without keys |
test_openai_provider_creation |
Yes | Sends a request with a dummy key and expects ApiError or HttpError; any failure passes |
test_huggingface_provider_creation |
Yes | Asserts nothing |
Unit tests test_mock_embeddings and test_default_provider are in the module. (source: tests/embeddings_test.rs; src/protocol/http/embeddings.rs, tests)
Not verified: nothing in the snapshot tests the OpenAI or HuggingFace paths against a live or stubbed server.
Differences from docs/EMBEDDINGS.md
docs/EMBEDDINGS.md describes only the HTTP providers. It does not mention the vector service embedders, the SYNERGYDB_EMBED_* variables or the hash embedder, which are what vector collections use. Its cost and rate figures are not backed by anything in the code. (source: docs/EMBEDDINGS.md; src/vector/embed.rs)
| Item | Vector service | HTTP endpoint |
|---|---|---|
| Offline default |
hash, lexical |
Mock, random-looking per text |
| Default dimensions | 384 | 1536 |
| Default model name | nomic-embed-text |
text-embedding-3-small |
| Provider error | Returned to the caller | Replaced by mock vectors |
(source: src/vector/embed.rs; src/protocol/http/embeddings.rs; src/protocol/http/routes.rs, generate_embeddings)
Third-party crates
reqwest 0.12 (optional, behind rest-api) for HTTP, tokio for the runtime, serde_json for request bodies and base64 for the base64 output format. (source: Cargo.toml)