The Problem
Here is a search assistant over a company's internal documents. It ranks documents by how many words they share with the question. That is cruder than anything you would ship, but close to a lot of first demos, and in the demo it answered every question well.
Read it, then predict what a new employee sees when they ask how much annual leave they get.
DOCS = [
{"id": "handbook-leave", "groups": ["staff"],
"text": "Annual leave is 25 days a year, booked in HR."},
{"id": "review-j-lee", "groups": ["hr"],
"text": "Review, J. Lee: pay frozen, annual leave on hold."},
{"id": "oncall-policy", "groups": ["eng"],
"text": "A weekend on call earns a day of leave in lieu."},
{"id": "board-notes", "groups": None,
"text": "Board notes: plan to cut annual leave carry-over."},
{"id": "handbook-sick", "groups": ["staff"],
"text": "Sick leave is separate from annual leave."},
]
def score(query, text):
words = {w.strip(".,:?").lower() for w in text.split()}
asked = [w for w in query.lower().split() if len(w) > 2]
return sum(w in words for w in asked)
def search(query, k=2):
def by_score(d):
return score(query, d["text"])
ranked = sorted(DOCS, key=by_score, reverse=True)
return [d["id"] for d in ranked[:k] if by_score(d) > 0]
print(search("how much annual leave do I get"))
The second result is a colleague's performance review. The ranking did its job: the review really does mention annual leave. What the demo never asked is who is reading. When you presented it, that didn't matter, because you had seen every document. Inside the client's company it is the first thing their security team will try.
Nothing here is a model problem. A better embedding model would rank the review higher still, because it is relevant. The problem is everything around the model: whose documents these are, who may read them, and what to do when nobody wrote that down. The distance between "works in the demo" and "works for everyone at the client" is where forward deployed engineers spend their time.
This lesson is free
You've read the first 2 sections. The rest covers The Concept, Build, Check Yourself, Key Terms & Next. A free account opens all of it, with its practice questions and its lab. No card.
Create a free account — the opening phases of 29 of 35 courses, and the first lesson of every phase, are free, no credit card.