Trending

World technology news

→
Vector Databases 2/5: Neural Networks and Embeddings
Software Engineering · 2026
Software Engineering

Vector Databases 2/5: Neural Networks and Embeddings

Explore how neural networks learn semantic representations, including Transformers, pooling, training objectives and embedding model selection.

Developer's JournalPublished: Nov 26, 20265 min read
Reading progress0%

How a neural network learns a vector

A neural network transforms input through parameterized layers, for instance y = f(Wx + b). During training a loss function measures the discrepancy from a target and gradient-based optimization updates the weights. An embedding network learns a useful representation space rather than necessarily predicting a single category. The model learns the geometry; the database stores and retrieves its outputs.

Tokens, Transformers and context

A tokenizer converts text to token IDs, and model layers update initial token representations using contextual information. Transformer self-attention captures relationships between positions, helping distinguish apple as fruit from Apple as a company. It is not perfect comprehension. Respect the model's maximum sequence length: truncation can silently discard important details near the end of a long document.

Database access flowConceptual sketch · summary of the article's technical flow
Original technical illustration; conceptual, not a measured result.

Pooling, dimensionality and normalization

Transformer encoders typically produce one representation per token. A sentence embedding may use masked mean pooling, a special token or a learned projection, depending on the model. Follow the documented output procedure. Unit normalization makes cosine comparisons consistent. More dimensions do not automatically mean better relevance; training data, language coverage, latency and storage all matter. The multilingual MiniLM sentence encoder is a 384-dimensional example.

Contrastive learning and hard negatives

A positive pair may connect travelling with my dog to a pet-friendly property; a hard negative could be a property that explicitly refuses pets. Contrastive objectives seek relatively closer relevant pairs and more distant inappropriate pairs. Hard negatives expose lexical shortcuts, negation errors and numerical confusion. Domain bias and training data also influence results. Evaluate with your own Turkish queries rather than trusting a generic benchmark alone.

Bi-encoders and cross-encoders

A bi-encoder embeds queries and documents separately, allowing document vectors to be indexed in advance. A cross-encoder processes a query-document pair jointly to score relevance. Scoring every document jointly is expensive at scale, so a common design retrieves candidates with a bi-encoder and reranks a small subset using a cross-encoder. Choose candidate counts through measurement, and enforce authorization independently.

Generate real embeddings in Python

Install sentence-transformers in an isolated Python environment, load a multilingual model and encode two short sentences. The first run may download weights; check licensing, storage and hardware requirements. The accompanying example calculates the dot product of normalized vectors. Observe actual scores locally; no benchmark result is claimed here. Try sentences with opposite meaning to expose limitations, and protect exact constraints with metadata filters.

from sentence_transformers import SentenceTransformer

model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
v = model.encode(['Orman içinde sakin konaklama', 'Doğada sessiz bir tatil'], normalize_embeddings=True)
print(v.shape)
print(float(v[0] @ v[1]))

Model selection, upgrades and measurement

Track model identity, revision, token limit, normalization, dimensions, supported languages and creation time with each index version. When changing the embedding model, build a new collection and re-embed documents instead of mixing incompatible spaces. Measure latency, memory, Recall@K and false positives on Turkish queries. Compare at least two candidates on a small labelled evaluation set. Versioning makes migration and rollback auditable.

Sources and all five chapters

This is part 2 of a five-part series. Start with the foundations or jump directly to another chapter. The links below lead to the other articles in the same series, followed by primary technical references. Code listings are educational examples; evaluate performance and model relevance in your own environment.

1 reads ✎ Write a comment

Reader discussion

Discussion prompt

Bu gelişmeyi kendi alanınızda uygulamadan önce hangi veriyi doğrulamak isterdiniz?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.