A support ticket about an internet connection that keeps dropping should match a resolved ticket about unstable WiFi, even though their words differ. BERT can capture sentence context, but scoring each new ticket jointly with every stored ticket requires a separate model pass for every pair. Against 100,000 tickets, that makes routing too slow for an interactive search. section 2.3
Sentence-BERT replaces pairwise encoding with a bi-encoder: the query and each stored text pass independently through the same BERT encoder. Shared weights put their sentence embeddings in a comparable space. Pooling, usually by averaging token vectors, produces one vector per sentence; training pulls semantically similar pairs together and pushes unrelated pairs apart. section 2.3.1
Separate indexing work from request-time work:
- Encode stored tickets once and retain their embeddings. section 2.3.1
- Encode each incoming query with the same model, then compare its vector with stored vectors to rank matches. section 2.3.2
- For large collections, pair the embeddings with an approximate vector index such as FAISS rather than relying on model inference for every candidate pair. section 2.3.4
Listing 2.5 Practical sentence-level similarity with Sentence-BERT.
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2') #A
tickets = [ #B
"My internet connection keeps dropping",
"WiFi connectivity is unstable",
"Billing question about charges"
]
ticket_embeddings = model.encode(tickets) #C
query = "Network connection problems" #D
query_embedding = model.encode([query])
similarities = model.similarity(query_embedding, ticket_embeddings) #E
print(f"--- Similarities for query: '{query}' ---")
for i, score in enumerate(similarities[0]):
print(f"Score: {score:.3f} | Ticket: '{tickets[i]}'")
The Python listing loads a pretrained sentence-transformers model, encodes three ticket titles and a new query, then compares their embeddings. section 2.3.2
Matching across different wording
For “Network connection problems,” the connection-dropping and unstable-WiFi tickets score 0.620 and 0.565; an unrelated billing ticket scores 0.048. These scores illustrate semantic matching, not a guarantee that every domain will rank as cleanly. section 2.3.2
The tradeoff moves expensive model work toward indexing, not away entirely: encoding a million documents remains a batch job. Quality depends on training data and domain fit, while BERT’s 512-token limit constrains input length. Domain fine-tuning needs labeled pairs and a loss choice; try better retrieval or a reranker before assuming fine-tuning is the simplest fix. section 2.3.3


