Corpus Search API
Vector search across a Pinecone media corpus with AI-powered query expansion, metadata extraction, timezone-aware filtering, proximity re-ranking, and optional LLM semantic re-ranking via Claude.
Only query is required. Everything else is optional — the AI figures out strategy, time, location, and type from natural language.
https://corpus.collectivememory.ai
Quick Start
Three examples to get you going — from fully automatic to fully manual.
Search
Runs the complete search flow in one call: AI extraction → expansion → embed → Pinecone query → post-filter → proximity re-rank → optional LLM re-rank.
query are optional — AI fills in strategy, time, and location if extractMeta is enabled.| Parameter | Type | Default | Description |
|---|---|---|---|
| query required | string | Natural language search text | |
| expand | boolean | true | Claude enriches the query with 5–15 contextual keywords before embedding |
| extractMeta | boolean | true | Claude infers strategy, time preset, location, and media type from the query |
| timezone | string | "UTC" | IANA timezone for time preset resolution. If AI detects a location, that timezone overrides this. |
| strategy | string | AI decides | Search strategy — omit to let AI choose. See strategy table below. |
| timePreset | string | AI decides | Time window: today, tonight, yesterday, this_week, last_week, this_month, last_30d, last_90d, all |
| startMs | number | Explicit time range start (UTC ms). Overrides timePreset. | |
| endMs | number | Explicit time range end (UTC ms). Overrides timePreset. | |
| type | string | Media type filter: image, video, text, audio | |
| lat | number | AI decides | Reference latitude for proximity re-ranking |
| lng | number | AI decides | Reference longitude |
| radiusKm | number | 50 | Proximity boost radius in km |
| weight | number | 0.15 | Proximity boost weight (0–1). Higher = location matters more. |
| country | string | Exact country metadata match (Pinecone pre-filter) | |
| city | string | Exact city metadata match (Pinecone pre-filter) | |
| topK | integer | 100 | Max results. Range: 1–10,000 |
| filterMode | string | "pre" | "pre" = Pinecone-level filter (faster). "post" = server-side filter. |
| rerank | boolean | false | Enable LLM semantic re-ranking via Claude |
| rerankPool | integer | 10 | Candidates to feed into Claude for re-ranking |
| rerankReturn | integer | 5 | Results to return after LLM scoring. Must be ≤ rerankPool. |
| Attention Filter | |||
| attnMin | number | Minimum ATTN score. Only returns results where attn ≥ attnMin. Applied as a Pinecone pre-filter (or post-filter depending on filterMode). Range: 0–100,000. | |
| Claude Settings | |||
| claudeModel | string | claude-sonnet-4-20250514 | Claude model for AI calls. Options: claude-sonnet-4-20250514, claude-haiku-4-5-20251001 (cheapest), claude-sonnet-4-6, claude-3-5-sonnet-20241022 |
| anthropicKey | string | server env | Your own Anthropic API key. If omitted, uses the server's default key. |
| Value | Behavior |
|---|---|
embed | Pure vector similarity — no time or location filtering |
embed_time | Vector + time window filter |
embed_time_meta | Vector + time + city/country string match |
embed_time_coord | Vector + time + coordinate-based proximity re-ranking |
Metadata Extraction
| Parameter | Type | Description |
|---|---|---|
| query required | string | Natural language query |
| timezone | string | IANA timezone for context |
| claudeModel | string | Override Claude model (e.g. claude-haiku-4-5-20251001) |
| anthropicKey | string | Your own Anthropic API key |
| Parameter | Type | Description |
|---|---|---|
| query required | string | Query to expand |
| claudeModel | string | Override Claude model (e.g. claude-haiku-4-5-20251001) |
| anthropicKey | string | Your own Anthropic API key |
Embedding & Query
gemini-embedding-001.| Parameter | Type | Description |
|---|---|---|
| text required | string | Text to embed |
| Parameter | Type | Description |
|---|---|---|
| vector required | number[] | 768-dim embedding |
| host required | string | Pinecone host (from /api/resolve-host) |
| topK | integer | Max results (default 100) |
| filter | object | Pinecone metadata filter |
/api/query.Geocoding
| Parameter | Type | Description |
|---|---|---|
| q required | string | Place name to geocode |
Performance
| Step | Duration | Notes |
|---|---|---|
| AI extraction | 1–2s | Claude call. Parallel with expansion. |
| AI expansion | 1–2s | Claude call. Parallel with extraction. |
| Embedding | 200–400ms | Gemini API |
| Pinecone query | 300–800ms | Depends on topK and filter |
| Firestore fetch | 300–600ms | Only if rerank=true |
| LLM rerank | 2–5s | Only if rerank=true |
Total without rerank: ~2–4s. With rerank: ~5–9s. Set expand: false and extractMeta: false for ~1s latency.
Priority Order
When multiple sources provide the same parameter:
| Status | Cause |
|---|---|
400 | Missing required parameter |
405 | Wrong HTTP method |
500 | Internal error (Pinecone, Claude, Gemini, or Firestore) |
AI steps fail gracefully — a failed extraction uses defaults, a failed expansion embeds the raw query, a failed rerank returns null. The search still returns results.
Corpus Stats
Live statistics from the corpus Firestore metadata, Cloudflare Media Stream, and the application database (accessible via BigQuery).
| Source | Contains | Access |
|---|---|---|
Corpus Firestore | Document metadata, backfill state, processing cursors | Firestore SDK |
Cloudflare Stream | Video hours, stream counts, encoding stats, media metadata | CF API |
App Database | Entity counts, image counts, user data, content stats | BigQuery |
Pinecone | 768-dim vectors, metadata fields per record | /api/query |
Full corpus stats — entity counts, video hours, image counts, and other aggregate metrics — will be surfaced on the corpus homepage via BigQuery and Cloudflare Stream API. See the Roadmap for details.
Roadmap
Planned features and infrastructure work, organized by priority. Items marked Active are in progress.
Active Corpus Homepage Stats
Surface aggregate corpus statistics on the search homepage — entity counts, total images, video hours, media breakdown by type, geographic distribution. Data pulled from BigQuery (app database) and Cloudflare Stream API.
Active Cloudflare Media Stats Integration
Pull video duration, encoding status, storage, and stream-level metadata from Cloudflare Stream into corpus stats. Currently video data lives in Cloudflare but isn't aggregated into the corpus dashboard.
Next Memory Benchmarking
Benchmark memory infrastructure against established evaluation frameworks to validate retrieval quality, temporal reasoning, and long-context recall before launch.
Active Live ATTN Score Architecture
Live attention score filtering is now available. The attnMin parameter on /api/search filters results by minimum ATTN score. The UI includes a slider (0–100k) with manual input. Results can be sorted by ATTN in the search UI.
- Remaining: ATTN scoring service → real-time Pinecone metadata update → Firestore ATTN field sync
Next Downloadable Data Sample
Allow visitors and potential integrators to download a representative JSON sample of corpus records — covering all media types — to explore the data schema and content structure without needing API access.
Planned BigQuery Stats Pipeline
Scheduled aggregation of app-level stats (entities, images, user counts) from the application database via BigQuery, surfaced on the corpus homepage and available as a stats API endpoint.
Planned Model-Agnostic Embedding Swap
Support runtime selection of embedding providers — the corpus stores media and metadata, not vectors. At query time, pick Gemini, OpenAI, Cohere, or any provider. Re-embedding happens lazily or in batch.
User Memories
Retrieve all memories stored in the corpus for a specific user. Pass a nickname or a raw userId — the API resolves nicknames automatically via the Patr user database.
user param — either a nickname or a direct userId. The API first queries the Patr users collection for a matching nickName (case-insensitive). If found, it uses that user's internal ID to query the selected source. If no nickname match, it falls back to treating the input as a raw userId. Results sorted by createdAtMs descending, paginated server-side.| Parameter | Type | Default | Description |
|---|---|---|---|
| user required | string | Nickname or userId. Nickname is resolved first; falls back to direct userId. Alias: userId | |
| source | string | pinecone | pinecone or firestore. Pinecone is ~50% backfilled — use firestore for complete data. |
| pageNumber | integer | 1 | Page number (1-indexed). Alias: page |
| pageSize | integer | 20 | Results per page. Range: 1–100. Alias: limit |
source=firestore to query the full dataset. Use source=pinecone (default) for the vector-indexed subset. Both return the same response shape.
user value is first looked up as a nickName in the Patr users collection (case-insensitive). If a match is found, the user's internal ID is used. If no match, the value is used directly as a userId. The response includes resolvedVia ("nickname" or "userId") so you know which path was taken.
| Field | Type | Description |
|---|---|---|
| userId | string | Resolved internal user ID used for the query |
| nickName | string|null | Matched nickname, or null if resolved via direct userId |
| resolvedVia | string | "nickname" or "userId" — which lookup path succeeded |
| source | string | "pinecone" or "firestore" — which backend was queried |
| totalCount | integer | Total number of memories for this user across all pages |
| page | integer | Current page number (1-indexed) |
| pageSize | integer | Number of results per page (as requested) |
| totalPages | integer | Total number of pages — ceil(totalCount / pageSize) |
| hasMore | boolean | true if there are more pages after the current one |
| timespan | object|null | Date range of memories. Pinecone: spans all user memories. Firestore: spans the current page. Fields: earliestMs, latestMs, earliest (ISO), latest (ISO) |
| memories | array | Array of memory objects for the current page, sorted newest first |
| timing | object | Timing breakdown: resolveMs, pineconeMs/firestoreMs, totalMs |
More Memory Endpoints
Additional memory endpoints planned for future releases. Memory quality will be validated against benchmarks (see Roadmap).
Planned City Memories
Aggregate knowledge about specific cities — trending topics, recurring events, notable locations, local context. Powers location-aware search enrichment and city-specific AI behavior.
Planned Location Memories
Fine-grained coordinate-based memories — what has happened at specific GPS coordinates over time. Enables hyper-local search context and spatial pattern recognition.
Planned Event Memories
Temporal event tracking — significant events detected across the corpus with time, location, and topic clustering. Supports event-aware search and timeline queries.