Skip to content

Refactor search analytics#2

Open
CahidArda wants to merge 4 commits into
upstash:mainfrom
CahidArda:refactor-search-analytics
Open

Refactor search analytics#2
CahidArda wants to merge 4 commits into
upstash:mainfrom
CahidArda:refactor-search-analytics

Conversation

@CahidArda
Copy link
Copy Markdown

No description provided.

CahidArda added 4 commits June 1, 2026 22:42
Replace @upstash/core-analytics with a direct Redis Search implementation.

- Store each citation as a hash per (dimensions, hour) at
  <prefix>:event:<data-hash>:<hourInt>; a Lua script HINCRBYs the counter
  and writes metadata + TTL (default 28d, configurable) on first hit.
- Order-independent data-hash; hourInt kept internal (public API uses Date).
- Add AgentAnalytics.query namespace (aggregateBy, timeseries, getIndex,
  dropIndex) backed by a search index over the event hashes.
- Make keyPrefix/eventKey protected.
- Move implementation under src/; trim public surface to AgentAnalytics + types.
- Add unit + live integration tests.
aggregateBy/timeseries no longer call waitIndexing implicitly; callers
invoke query.waitIndexing() when they need read-after-write consistency.
…sing

aggregateBy/timeseries now query via redis.search.index (a local handle, no
round-trip) instead of createIndex, so each read is a single request. The index
must be created once via query.getIndex(); querying a missing index now throws a
clear IndexNotFoundError (a describe() round-trip is paid only on the error
path) instead of an opaque TypeError.
- aggregateBy({ field, since, until? }) and timeseries({ since, until?, groupBy? })
  now each take one options object (AggregateByOptions / TimeseriesOptions).
- Add scripts/seed.ts (bun run seed): writes 30 days of hourly history with
  diurnal/weekly patterns and deliberate empty buckets, then creates the index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant