From discrete to continuous values: why AI needs vectors, not hash keys
A hash table maps a key to a value: search for "cat" and you find "cat" or nothing. AI systems represent meaning as vectors of decimal numbers, so "cat" and "kitty" sit close together and a search for one can find the other. Discrete structures answer "is it the same?", continuous ones answer "how close is it?", and production systems need both: exact lookups for IDs and order numbers, vector search for meaning.
Discrete values
Discrete values are separate, countable values: 1, 2, 3, true, false, "TS9120". Each one stands on its own. There's nothing between 3 and 4, and the difference between "apple" and "banana" means nothing.
Classic data structures are built for them. A hash table gives "cat" a hash, puts it in a bucket, and finds it again in constant time. Search for "kitty", and you get nothing, because "kitty" has a different hash and lands in a different bucket.
Continuous values
Continuous values are real numbers: after 3 comes 3.1, 3.01, 3.001. Distance between them means something.
AI represents a word, a sentence or an image as a vector of many continuous values, its embedding. A single number can't carry the meaning of a word like "upgrade", but a vector of hundreds of numbers can, because each dimension captures part of how the word is used. Words used in similar ways end up with similar vectors. Plot them, and "fan", "light" and "bulb" sit together, "charger" and "battery" sit together, and "king" sits near "queen".
Hash lookup vs vector search
import math
index = {"cat": 84102, "car": 11870}
print("hash lookup for 'kitty':", index.get("kitty"))
vectors = {"cat": [0.8, 0.6], "kitty": [0.79, 0.62], "car": [0.1, -0.9], "piano": [-0.3, 0.9]}
def cosine(a: list[float], b: list[float]) -> float:
dot = sum(x * y for x, y in zip(a, b))
return dot / (math.hypot(*a) * math.hypot(*b))
ranked = sorted(vectors, key=lambda w: -cosine(vectors["kitty"], vectors[w]))
print("nearest to 'kitty':", ranked)
The hash table returns nothing. The vector search returns "kitty" itself, then "cat".
Comparison
| Discrete | Continuous | |
|---|---|---|
| Values | Integers, booleans, exact keys | Floating-point numbers in vectors |
| Question | Equal or not? | How similar? |
| Structures | Hash table, tree, list | Vector, tensor, vector index |
| Distance | No meaning | Meaning (cosine, Euclidean) |
| Example | orders["TS9120"] |
Nearest vectors to "kitten" |
| Good for | IDs, exact values, permissions | Meaning, paraphrases, intent |
You still need both
An order number, a customer ID or an amount needs an exact lookup, because "close to TS9120" is wrong. A question like "can you get medicine for someone" needs meaning: keyword search finds pages containing "medicine" and "someone", and misses that the person wants to buy medicine at a pharmacy on someone's behalf. That's why production search combines keyword and vector search. See hybrid search.
Check your understanding
Explain why an order ID needs keyword or exact search and a paraphrased question needs vector search. If you can, this module has done its job.
From the floor
In the AI data structures lecture, I used Google search to show the shift: early keyword search returned pages containing the exact words you typed, like "best data scientist in India", while today's search understands context and intent, and the change underneath is the move from discrete keys to continuous vector representations, which is also why searching "automobile" can return a page about cars.
When a builder asked what discrete versus continuous meant in practice, my answer was that a number like 7 gives you no information beyond being 7, and the hash value 84102 for "cat" only lets you find "cat" if you have that exact key, while a vector representation lets you find meaning, which is why you use hashes for exact values and vectors for meaning.