SESSION / working transcript
Freshness and semantic search: How to?
As the number of notes grows exponentially, search needs to keep up. This session present how I integrated freshness at the root search in my deep-obsidian-mcp search engine.
As the knowledge base grows, the results are getting harder to organise. I was thinking: should I add a weight based on a note’s age to my hybrid search? Maybe using the last modification date? Something really small, just enough to have an impact within the same semantic meaning. Don’t do anything yet, let’s just study it.
Yes, I think it’s worth exploring: when relevance is close, slightly favouring the more recent note could help retrieve the current state of a project.
I’d start with a small multiplicative bonus after the relevance ranking. As a hypothesis to test: a 2% weight and a 90-day half-life.
\begin{aligned}
f(t) &= 2^{-\frac{t}{h}} \\[0.8em]
s_{\mathrm{final}} &= s\,\bigl(1 + w\,f(t)\bigr)
\end{aligned}Here, t is the note’s age in days, h = 90 days is the half-life, s is the relevance score, and w = 0.02 is the maximum freshness bonus.
The idea behind freshness is mainly for decisions from two years ago. I don’t want you taking them at face value if we’ve reworked things repeatedly since then.
Yes, I understand better: you mainly want to avoid an old decision being interpreted as the current state of the project when later work has changed it.
Freshness can help bring up that later work. But it isn’t enough to establish which decision holds: an old note may still be valid, and a simple correction can give it a recent modification date.
Yes, but with the number of notes growing exponentially, I don’t know whether you’ll still get them all in the results for a topic two or three years from now. If there are tens of thousands of notes in the vault.
Yes, you’re right: my proposal relied too much on recent notes already being in the results. With tens of thousands of notes and a limited candidate set, that isn’t guaranteed. I could receive a very well-written old decision without ever seeing the sessions that replaced it.
That changes where freshness needs to intervene: a bonus applied only at the end cannot bring back a note already eliminated during search.
Hmm, because by that point you’ve already cut the results down, basically? How does that work?
Yes. There is an initial selection before the graph bonus, then a final cutoff.
If I ask for eight results, the semantic search keeps its top 64 and the lexical search keeps its top 64. We merge those lists with RRF, apply the graph bonus, then keep the top eight.
A recent note whose passages appear in neither of those initial lists never reaches the bonus. Even an enormous freshness bonus applied afterwards couldn’t retrieve it.
Can we apply freshness during the search, before it’s bounded?
Yes, we can incorporate freshness before the first cutoff, when calculating each passage’s relevance.
For vector search, retrieving the nearest neighbours first and then applying freshness would still mean selecting from a bounded set. To do it strictly across the whole corpus, we would either need to calculate the combined score for every vector or use a search mechanism that incorporates this signal. The cost would need measuring.
Couldn’t that technically go straight into the vector?
Yes, technically we can incorporate a time component into the vector used for search.
We need to distinguish putting the date in the text sent to the embedding model from adding a time dimension to the resulting vector. With the second approach, we explicitly control its weight in the distance calculation. There is research on vector transformations that incorporate time decay into the search score. The approach is possible, but it needs a suitable mathematical construction.
Okay, and what does the research paper say about a formula we could use?
The paper proposes combining meaning and freshness in the search score, before candidate selection. It presents an additive formula and a multiplicative one.
For your needs, I’d favour the additive formula, giving meaning a very strong priority. As a starting point to evaluate:
\begin{aligned}
&f(t) = 2^{-\frac{t}{h}} \\[0.8em]
&S = 0.98\,s + 0.02\,f(t)
\end{aligned}Here, s is semantic similarity, t is the note’s age in days, and h = 90 days is the half-life.
Okay, but that’s basically what you said before? In terms of performance, we’re not getting what we were talking about with putting it into the vector.
Yes, you’re right.
At indexing time, we transform each embedding with its time factor. At search time, we transform the query vector using the current date. The index directly searches for the best vectors according to the combined score, then returns the candidates.
Okay, and that’s still additive? How do we know the new dimension only has a 2% weight? I don’t quite get it.
“But SQLite does the distance calculation, doesn’t it?”
Yes, it is still additive. With a dot product, we multiplies matching coordinates and then adds them.
We choose the coordinates to produce the sum we want. The 2% weight comes from the coefficients we put into those coordinates. An extra dimension doesn’t automatically have the same weight as the others.
\begin{aligned}
S_{\mathrm{semantic}} &= \bigl(\sqrt{0.98}\bigr)^2\,s \\
&= 0.98\,s \\[0.8em]
S_{\mathrm{time}} &= \bigl(\sqrt{0.02}\bigr)^2\,g z \\
&= 0.02\,f(t)
\end{aligned}Here, s is semantic similarity. The query time factor g and the note time factor z are chosen so that g z = f(t).
One detail about the wording: here, “2%” means the coefficient of the time term, not a 2% increase in the score.
But SQLite is already calculating with Euclidean distance through MATCH, isn’t it? Adding a time coordinate wouldn’t make it switch to a dot product.
Exactly. MATCH would still calculate Euclidean distance. The paper’s construction gives us a dot product, so keeping our native SQLite search requires another transformation that reproduces the same ranking.
Okay, so sqlite-vec couldn’t calculate our search anymore?
No ! It could still calculate it using its Euclidean MATCH.
There is an exact transformation from dot-product search to Euclidean-distance search. It adds a compensation coordinate that neutralises the effect of different vector lengths.
%%{init: {"flowchart": {"htmlLabels": false}}}%%
flowchart TD
A["Text embedding<br/>D dimensions"]
B["Add time<br/>D + 1 dimensions"]
C["Add L2 compensation<br/>D + 2 dimensions"]
D["sqlite-vec MATCH<br/>Euclidean distance"]
A --> B --> C --> Dd^2 = C - 2SHere, C is constant for a given query, and S is the score.
Minimising this distance is equivalent to maximising the score we want. SQLite keeps calculating Euclidean distance; it’s our vector preparation that makes it represent meaning and freshness.
I think I’m going to need a massive PDF, like an absolutely mad maths course, to understand all this lol. I’m up for it. And explain the bound on vector lengths now.
Here, “length” means the vector’s norm, not its number of coordinates. We add a compensation coordinate so all stored note vectors have the same norm. With a bound of 10 and an initial norm of 6, the extra coordinate is 8: 6² + 8² = 10².
To keep that compensation valid for future notes, we can choose a reference date a little way into the future. As long as note dates stay before it, their time factor remains at most 1, giving us a known bound.
Choose a reference date a little way into the future.
And how far into the future we choose has no impact?
In exact arithmetic, the reference date doesn’t change the ranking: it cancels out between the note and query factors.
In practice, though, it does have an impact. A very distant reference date creates tiny factors for notes and huge factors for queries, which can degrade numerical precision. A reference date that’s too close needs updating sooner.
Okay, but that’s annoying. So we have to choose a date close enough to keep our vectors precise, but far enough away to give us some room before reindexing?
Yes, this construction does introduce that tradeoff.
This looks so complicated and cool it’s scary. Technology is insane lol.
But then the advantage is that we can choose how much freshness matters in the configuration without reindexing, right?
Yes, and we can even design the stored vectors so that changing the weight doesn’t require rebuilding the index. The trick is to put the coefficients on the query side.
\begin{aligned}
\mathbf n &= [\mathbf x;\,z;\,c] \\[0.8em]
\mathbf u &= [\alpha\mathbf q;\,\beta g;\,0]
\end{aligned}The stored note n contains its semantic vector x, time factor z, and compensation c. The query u contains its semantic vector q and time factor g, weighted by α and β.
I need more details
I owe you the proof.
The stored note has a semantic vector x of norm 1 and a time factor z between 0 and 1. Its squared norm is always 1 + z² + (1 − z²) = 2.
\begin{aligned}
\mathbf n &= [\mathbf x;\,z;\,\sqrt{1-z^2}] \\
\mathbf u &= [\alpha\mathbf q;\,\beta g;\,0] \\[0.8em]
d^2 &= 2 + \alpha^2 + \beta^2 g^2 - 2\bigl(\alpha s + \beta f(t)\bigr)
\end{aligned}Here, q is a unit semantic query vector, g is its time factor, s is the semantic similarity between q and x, and f(t) = g z.
For a given query, 2 + α² + β²g² is identical for all notes. Minimising distance therefore maximises the score in brackets. The two extra dimensions remain in the index, and MATCH remains Euclidean.
My communication mistake was changing the construction without showing you why it remained compatible.
# Editorial verification — rerun for this post
$ python3 verify_freshness_geometry.py
3,000 random cases passed (8 semantic dimensions).
Maximum absolute error: 8.88e-16
Identity check only; not a search-quality or performance benchmark.The PDF attached is 19 pages long, with both constructions, proofs, a complete example, precision issues and exercises with solutions.
Okay, that’s for semantic search. What engine do we use for keywords?
For keywords, your engine uses BM25 written in Rust, with SQLite retrieving the passages that contain the terms. To add freshness here, we could adjust each BM25 score before sorting and the first cutoff. No vector transformation or time bound needed.
Okay, I’ve read the whole course. First create a vault with enough synthetic data for tests. Then we test the settings before integrating it.
I’ve prepared a synthetic vault of 10,000 notes with 576 annotated questions, split between calibration and independent validation. The native tests on this Mac with NEON give median search times of 48.12 ms for 4096 dimensions and 48.20 ms for 4098. No big impact for our new search.
So 90 days means half the bonus after three months? We can still distinguish notes a few weeks apart, then? Test the reference dates to see how far ahead we can go without losing precision.
Exactly. Only the freshness contribution halves; an old note doesn’t lose half its semantic relevance every three months.
The first tests show a fairly clear limit: up to 18 months, numerical error stays close to what we observed with an immediate reference date. At three years, weekly differences start to be disrupted; at five years, the representation loses a lot of precision.
Perfect and what about BM25 ?
The held-out projects confirm that the bonus helps: in the dense vault, the current decision goes from appearing among the candidates in two cases out of 12 to nine out of 12. They don’t distinguish 2% from 3% on that criterion, though; the choice of 3% comes from calibration.
I’m keeping 1% / 3% / 5% as the proposal for approval. The templates are still simple, and hybrid validation with the real model remains to be done.
No, let’s go with that, it looks pretty good to me. Implement it.
The implementation now passes 858 tests, including a hybrid test that retrieves the recent note before both cutoffs, then applies the usual RRF without a final time bonus.