Under the hood
How I use MongoDB Atlas
Everything I know about the business lives in MongoDB Atlas. Each card below ran live just now, through the same code the rest of the dashboard uses, and shows the exact query it sent.
Hybrid Search
Words and meaning, merged
One search box: “milk supplier” finds the dairy by meaning and by keyword, merged by $rankFusion.
- Eastside Dairy Co · EDC-7702 · £128.50 · found by keyword + meaning
- Eastside Dairy Co · EDC-7764 · £149.60 · found by keyword + meaning
- Eastside Dairy Co · EDC-7725 · £140.20 · found by keyword + meaning
- Eastside Dairy Co · EDC-7781 · £149.60 · found by keyword + meaning
- Eastside Dairy Co · EDC-7748 · £154.80 · found by keyword + meaning
The query it sent
db.invoices.aggregate([
{
"$rankFusion": {
"input": {
"pipelines": {
"keyword": [
{
"$search": {
"index": "invoices_text",
"compound": {
"filter": [
{
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
}
],
"should": [
{
"text": {
"query": "milk supplier",
"path": [
"counterparty",
"line_items.description"
],
"score": {
"boost": {
"value": 2
}
}
}
},
{
"text": {
"query": "milk supplier",
"path": "invoice_number",
"score": {
"boost": {
"value": 3
}
}
}
},
{
"text": {
"query": "supplier",
"path": [
"counterparty",
"line_items.description"
],
"fuzzy": {
"maxEdits": 1
}
}
}
],
"minimumShouldMatch": 1
}
}
},
{
"$limit": 8
}
],
"meaning": [
{
"$vectorSearch": {
"index": "invoices_semantic",
"path": "search_text",
"query": {
"text": "milk supplier"
},
"filter": {
"business_id": "gaia-coffee"
},
"numCandidates": 50,
"limit": 8
}
}
]
}
},
"scoreDetails": true
}
},
{
"$project": {
"invoice_number": 1,
"counterparty": 1,
"direction": 1,
"amount": 1,
"currency": 1,
"issue_date": 1,
"due_date": 1,
"status": 1,
"needs_review": 1,
"line_items": 1,
"search_text": 1,
"counterparty_key": 1,
"created_at": 1,
"paid_at": 1,
"score": {
"$meta": "score"
},
"details": {
"$meta": "scoreDetails"
}
}
}
])db.invoices.aggregate([
{
"$search": {
"index": "invoices_text",
"compound": {
"filter": [
{
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
}
],
"should": [
{
"text": {
"query": "milk supplier",
"path": [
"counterparty",
"line_items.description"
],
"score": {
"boost": {
"value": 2
}
}
}
},
{
"text": {
"query": "milk supplier",
"path": "invoice_number",
"score": {
"boost": {
"value": 3
}
}
}
},
{
"text": {
"query": "supplier",
"path": [
"counterparty",
"line_items.description"
],
"fuzzy": {
"maxEdits": 1
}
}
}
],
"minimumShouldMatch": 1
},
"highlight": {
"path": [
"counterparty",
"line_items.description"
]
}
}
},
{
"$match": {
"_id": {
"$in": [
"6adcee03b988df76b3ce42da",
"6adcee03b988df76b3ce42dd",
"6adcee03b988df76b3ce42db",
"6adcbb7b1653c09794cd6248",
"6adcee03b988df76b3ce42dc",
"6adce27c25d8761ad7a30945",
"6adcbb7b1653c09794cd6243"
]
}
}
},
{
"$project": {
"highlights": {
"$meta": "searchHighlights"
}
}
}
])
Vector Search + Automated Embedding
Similar invoices and a price check
Atlas embeds every invoice itself (Voyage): a new bill is compared with the most similar earlier ones, so price creep shows up.
- Ember & Oak Coffee Roasters GR-2026-1048 is most like:
- Bow Lane Roasters · BLR-2209 (similarity 0.90)
- Eastside Dairy Co · EDC-7748 (similarity 0.77)
- Eastside Dairy Co · EDC-7764 (similarity 0.76)
- Eastside Dairy Co · EDC-7781 (similarity 0.76)
The query it sent
db.invoices.aggregate([
{
"$vectorSearch": {
"index": "invoices_semantic",
"path": "search_text",
"query": {
"text": "Ember & Oak Coffee Roasters | supplier bill (we pay) | GR-2026-1048 | House Espresso Blend (1kg); Decaf Espresso (1kg)"
},
"filter": {
"business_id": "gaia-coffee",
"direction": "payable"
},
"numCandidates": 50,
"limit": 5
}
},
{
"$match": {
"_id": {
"$ne": "6adce27125d8761ad7a30942"
}
}
},
{
"$limit": 4
},
{
"$project": {
"invoice_number": 1,
"counterparty": 1,
"direction": 1,
"amount": 1,
"currency": 1,
"issue_date": 1,
"due_date": 1,
"status": 1,
"needs_review": 1,
"line_items": 1,
"search_text": 1,
"counterparty_key": 1,
"created_at": 1,
"paid_at": 1,
"score": {
"$meta": "vectorSearchScore"
}
}
}
])db.invoices.aggregate([
{
"$vectorSearch": {
"index": "invoices_semantic",
"path": "search_text",
"query": {
"text": "Ember & Oak Coffee Roasters | supplier bill (we pay) | GR-2026-1048 | House Espresso Blend (1kg); Decaf Espresso (1kg)"
},
"filter": {
"business_id": "gaia-coffee",
"direction": "payable"
},
"numCandidates": 50,
"limit": 9
}
},
{
"$match": {
"_id": {
"$ne": "6adce27125d8761ad7a30942"
}
}
},
{
"$limit": 8
},
{
"$project": {
"invoice_number": 1,
"counterparty": 1,
"direction": 1,
"amount": 1,
"currency": 1,
"issue_date": 1,
"due_date": 1,
"status": 1,
"needs_review": 1,
"line_items": 1,
"search_text": 1,
"counterparty_key": 1,
"created_at": 1,
"paid_at": 1,
"score": {
"$meta": "vectorSearchScore"
}
}
}
])
Vector Search as memory
What I remember about your decisions
Your past yes/no and your reasons are recalled before I draft, so you never explain the same thing twice.
- Before chasing Hackney Hub Coworking, I recalled (4 decisions remembered):
- Similar case (0.83): 25 Oct: you said no to a firm reminder to Victoria Park Wedding Co (£455.00, 9 days overdue).
The query it sent
db.memories.aggregate([
{
"$vectorSearch": {
"index": "memories_semantic",
"path": "search_text",
"query": {
"text": "Hackney Hub Coworking | chasing a customer | Office coffee cart, 2 days; Pastry platter | friendly nudge | 3 days overdue | £450.00"
},
"filter": {
"business_id": "gaia-coffee",
"action_type": "invoice_reminder"
},
"numCandidates": 50,
"limit": 11
}
},
{
"$project": {
"approval_id": 1,
"ref": 1,
"action_type": 1,
"target_id": 1,
"invoice_number": 1,
"counterparty": 1,
"counterparty_key": 1,
"amount": 1,
"about": 1,
"days_overdue": 1,
"escalation_level": 1,
"decision": 1,
"via": 1,
"note": 1,
"edit": 1,
"outcome": 1,
"search_text": 1,
"at": 1,
"score": {
"$meta": "vectorSearchScore"
}
}
}
])
Atlas Search
Typo-tolerant names
“What if I put flat whte up 20p?” still finds Flat White: fuzzy matching on the menu.
- “flat whte” → Flat White
The query it sent
db.products.aggregate([
{
"$search": {
"index": "products_text",
"compound": {
"filter": [
{
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
}
],
"should": [
{
"text": {
"query": "flat whte",
"path": "name",
"score": {
"boost": {
"value": 3
}
}
}
},
{
"autocomplete": {
"query": "flat whte",
"path": "name"
}
},
{
"text": {
"query": "flat whte",
"path": "name",
"fuzzy": {
"maxEdits": 1
}
}
}
],
"minimumShouldMatch": 1
}
}
},
{
"$limit": 5
},
{
"$project": {
"name": 1,
"price": 1,
"score": {
"$meta": "searchScore"
}
}
}
])
Atlas Search autocomplete
Suggestions as you type
“eas” → Eastside Dairy Co, from an edgeGram index.
- “eas” → Eastside Dairy Co
The query it sent
db.invoices.aggregate([
{
"$search": {
"index": "invoices_text",
"compound": {
"filter": [
{
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
}
],
"must": [
{
"autocomplete": {
"query": "eas",
"path": "counterparty"
}
}
]
}
}
},
{
"$limit": 18
},
{
"$project": {
"counterparty": 1
}
}
])db.products.aggregate([
{
"$search": {
"index": "products_text",
"compound": {
"filter": [
{
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
}
],
"must": [
{
"autocomplete": {
"query": "eas",
"path": "name"
}
}
]
}
}
},
{
"$limit": 18
},
{
"$project": {
"name": 1
}
}
])
Atlas Search facets ($searchMeta)
Counts in one call
Invoices per supplier and status for the Finances chips.
- 17 invoices
- Eastside Dairy Co: 5
- Hackney Hub Coworking: 3
- Bow Lane Roasters: 1
- Broadway Market Traders Assoc.: 1
- status paid: 7
- status open: 6
- status overdue: 4
The query it sent
db.invoices.aggregate([
{
"$searchMeta": {
"index": "invoices_text",
"facet": {
"operator": {
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
},
"facets": {
"status": {
"type": "string",
"path": "status",
"numBuckets": 6
},
"direction": {
"type": "string",
"path": "direction",
"numBuckets": 6
},
"counterparty": {
"type": "string",
"path": "counterparty",
"numBuckets": 6
}
}
}
}
}
])
Atlas Search: near (dates + geo)
Local news ranked by soon and close
Events and news scored by how soon they start and how close they are to the pitch.
The query it sent
db.news.aggregate([
{
"$search": {
"index": "news_text",
"compound": {
"filter": [
{
"equals": {
"path": "business_id",
"value": "gaia-coffee"
}
},
{
"range": {
"path": "expires_at",
"gte": "2026-12-01 19:56:25.792104+00:00"
}
}
],
"mustNot": [
{
"exists": {
"path": "duplicate_of"
}
}
],
"should": [
{
"near": {
"path": "starts_at",
"origin": "2026-12-01 19:56:25.792104+00:00",
"pivot": 259200000,
"score": {
"boost": {
"value": 2
}
}
}
},
{
"near": {
"path": "published_at",
"origin": "2026-12-01 19:56:25.792104+00:00",
"pivot": 604800000
}
},
{
"near": {
"path": "location",
"origin": {
"type": "Point",
"coordinates": [
-0.0614,
51.5367
]
},
"pivot": 1000
}
}
]
}
}
},
{
"$limit": 4
},
{
"$project": {
"kind": 1,
"headline": 1,
"summary": 1,
"url": 1,
"source": 1,
"published_at": 1,
"starts_at": 1,
"distance_km": 1,
"expires_at": 1,
"search_text": 1,
"score": {
"$meta": "searchScore"
}
}
}
])
Time-series collection
Takings by day from every till line
Each till line is stored in a time-series collection: a week of takings in one aggregation.
- time-series collection: timeField “ts”, metaField “meta”, bucketed by hours
The query it sent
db.sales.aggregate([
{
"$match": {
"meta.business_id": "gaia-coffee",
"ts": {
"$gte": "2026-11-24 19:56:25.803152+00:00"
}
}
},
{
"$group": {
"_id": {
"$dateTrunc": {
"date": "$ts",
"unit": "day",
"timezone": "Europe/London"
}
},
"takings": {
"$sum": "$line_total"
},
"lines": {
"$sum": 1
}
}
},
{
"$sort": {
"_id": 1
}
}
])
Agent memory
Your latest decisions, as I remember them
Each one is a document in memories. Atlas embeds it with Voyage (Automated Embedding) for Vector Search to recall next time. I write back what happened after a chase.
- #6 · 25 Oct: you approved a firm reminder to Victoria Park Wedding Co (£455.00, 10 days overdue).
- #3 · 25 Oct: you approved paying Cup & Lid Supplies (£184.00, 5 days overdue).
- #2 · 25 Oct: you said no to a firm reminder to Victoria Park Wedding Co (£455.00, 9 days overdue).
- #1 · 25 Oct: you approved a final notice to Shoreditch Design Studio (£288.00, 21 days overdue).
Indexes
Atlas Search and Vector Search indexes
invoices_textoninvoices: Atlas Search, READYinvoices_semanticoninvoices: Vector Search, READY · Automated Embedding with Voyagevoyage-4products_textonproducts: Atlas Search, READYagent_log_textonagent_log: Atlas Search, READYboard_memos_textonboard_memos: Atlas Search, READYnews_textonnews: Atlas Search, READYnews_semanticonnews: Vector Search, READY · Automated Embedding with Voyagevoyage-4memories_semanticonmemories: Vector Search, READY · Automated Embedding with Voyagevoyage-4events_textonevents: Atlas Search, READY