Your property retriever finds a description, quotes it correctly, and answers as though it read the whole listing. You check the indexed text. It's a search-card summary. Lovely citation, wrong scope.
The catch works in both directions: fetching an exposé gives you deeper evidence, but it doesn't guarantee that every property detail is published. Missing text can't establish that a property lacks something.
Lab note 151: how should we index property descriptions so retrieval distinguishes a short discovery snippet from exposé evidence?
The same key carries different evidence
Our Immowelt listings Actor keeps the same field name across different acquisition paths.
description contains full text when a listing is detailed and the search-card summary otherwise.
With enrichment enabled, a finite maxDetails allowance can leave emitted listings at different evidence depths. Its default, 0, means enrich all emitted listings. Enrichment adds a request per listing, so fetching deeper text has a real acquisition cost.
Neither output position nor description length tells us which path produced a record. We use the presence of detailsEnriched, which marks an exposé page being merged.
This Example input requests a finite enrichment allowance; the client retrieves the emitted records for the filters below.
import json import os import tiktoken from apify_client import ApifyClient run_input = { "mode": "search", "city": "Berlin", "distributionType": "mieten", "estateType": "wohnung", "includeDetails": True, "maxDetails": 1, "maxItems": 5, } client = ApifyClient(os.environ["APIFY_TOKEN"]) run = client.actor( "vexaloom-labs/immowelt-germany-rent-and-buy-listings-scraper" ).call(run_input=run_input) if run["status"] != "SUCCEEDED": raise RuntimeError(f"Run requires review: {run['status']}") rows = client.dataset(run["defaultDatasetId"]).iterate_items() That status check is our ingestion policy. Interrupted collection can retain already-collected rows; accepting those rows should be a deliberate decision about corpus coverage.
The indexing split looks like this:
listing record ├─ exposé merge marker present → exposé evidence └─ marker absent → search-summary evidence ↓ discovery stays available exposé-only answers exclude it Relevance can't upgrade a summary
Suppose your retrieval route promises to answer from exposé text. A relevant summary can still win a similarity search unless depth is an actual filter.
Adding “prefer detailed listings” to the generation prompt doesn't enforce that boundary. The wrong evidence has already entered the context.
These helpers assign depth from the merge marker and enforce an explicit route policy.
def evidence_depth(row): return ( "expose_merged" if "detailsEnriched" in row else "search_summary" ) def route_accepts(depth, route): if route not in {"discovery", "expose"}: raise ValueError("Unknown retrieval route") return route == "discovery" or depth == "expose_merged" Those labels are our index metadata, not additional Actor fields.
The discovery route retains summaries because they can support useful, specific claims. The exposé route excludes them because relevance can't upgrade their coverage.
There's a related analysis trap: counting feature mentions across unequal descriptions confounds property characteristics with text depth. More prose offers more opportunities to mention a garden. Compare within depth groups, and treat missing mentions as unknown.
| Pipeline mistake | What breaks | Filter boundary |
|---|---|---|
| Treat every description as exposé text | Answers imply broader coverage than indexed | Evidence-depth route |
| Flatten description sections | Location claims lose their scope | Named sections |
| Clip text after attaching citations | Qualifiers or attribution disappear | Budget the complete evidence object |
| Fill context directly from chunk ranking | Verbose listings crowd out other properties | Listing identity |
A neighborhood claim becomes a property feature
The detailed output can include locationDescription, additionalDescription, and extendedInfoDescription alongside description.
Concatenating everything into an anonymous paragraph loses useful evidence boundaries. A neighborhood amenity mentioned in location text can become a property amenity in the answer. The embedding doesn't file a complaint.
We keep nonempty text under its original section name and skip absent sections without manufacturing replacement prose.
DESCRIPTION_SECTIONS = ( "description", "locationDescription", "additionalDescription", "extendedInfoDescription", ) def description_sections(row): for section in DESCRIPTION_SECTIONS: value = row.get(section) if isinstance(value, str) and value.strip(): yield section, value.strip() Empty fields are omitted by the Actor. Filling a missing section with “No additional features” would introduce a claim the source never made.
Section labels help the generator interpret evidence, but they aren't property facts themselves. For an amenity answer, require text that actually supports the property-level claim. Even an enriched record can warrant “the indexed text doesn't establish this.”
The token budget must include the citation
A longer description creates more chunks and consumes more context. Cutting the final context string to fit can remove a qualification while leaving the preceding assertion intact.
It can also separate text from its source metadata. That's an expensive way to manufacture an uncitable answer.
We budget each serialized evidence object, including its section, depth, identifier, source, and scrape timestamp. The splitter preserves Unicode characters and prefers a nearby line or word boundary.
encoding = tiktoken.get_encoding("cl100k_base") def pack(value): return json.dumps(value, ensure_ascii=False, separators=(",", ":")) def token_count(value): return len(encoding.encode(pack(value), disallowed_special=())) def fit_chunks(text, metadata, budget): chunk = {**metadata, "text": text} if token_count(chunk) <= budget: yield chunk return if len(text) < 2: raise ValueError("Evidence and provenance cannot fit the budget") midpoint = len(text) // 2 cut = text.rfind("\n", 0, midpoint + 1) if cut <= 0: cut = text.rfind(" ", 0, midpoint + 1) if cut <= 0: cut = midpoint yield from fit_chunks(text[:cut].strip(), metadata, budget) yield from fit_chunks(text[cut:].strip(), metadata, budget) This is a mechanical boundary, not a promise of semantic completeness. A relationship can cross chunks; questions requiring surrounding clauses need neighboring evidence.
Use the encoding appropriate to your generation model. The budget here covers evidence objects, so reserve room separately for instructions, the question, and the answer.
If attribution alone can't fit, the function raises. Silently dropping the source to rescue a chunk would defeat the filter.
Paragraph count shouldn't decide listing diversity
A detailed listing can produce more retrievable chunks than a summary. Taking the highest-ranked chunks directly can fill the context with the same listing wearing different paragraph numbers.
That weakens comparison questions: repeated evidence about a property isn't broader market coverage.
This context filter takes score-ordered hits, applies the depth route, and keeps the first fitting chunk per classifiedId.
def select_context( ranked_hits, route, max_listings=5, context_budget=2000 ): selected = [] seen = set() for hit in ranked_hits: if not route_accepts(hit["evidence_depth"], route): continue listing_id = hit["classifiedId"] if listing_id in seen: continue candidate = selected + [hit] if token_count(candidate) > context_budget: continue selected.append(hit) seen.add(listing_id) if len(selected) >= max_listings: break return selected Pass your retriever's ranked chunk dictionaries to this function. Fetch enough candidates upstream for grouping to have a chance; grouping can't recover listings missing from the candidate pool.
This policy suits breadth across listings. A detailed question about a particular property may need several sections, so give that route its own per-listing allowance.
Also, classifiedId groups listing identity. It doesn't establish that differently identified advertisements represent different physical properties. We'd rather leave that distinction unresolved than deduplicate homes by similar sales prose.
Export text with its evidence contract attached
Now we can produce JSONL for indexing without separating text from its provenance.
Records missing the attribution fields go into a review collection. Each exported line contains a chunk and the metadata needed to route it and build its citation.
chunk_budget = 300 provenance_fields = ("classifiedId", "sourceUrl", "scrapedAt") chunks = [] rejected = [] for row in rows: if not all( isinstance(row.get(field), str) and row[field].strip() for field in provenance_fields ): rejected.append(row) continue provenance = { field: row[field].strip() for field in provenance_fields } for section, text in description_sections(row): metadata = { **provenance, "section": section, "evidence_depth": evidence_depth(row), } chunks.extend(fit_chunks(text, metadata, chunk_budget)) jsonl = "".join(pack(chunk) + "\n" for chunk in chunks) The JSONL string is ready for an index adapter. Store the metadata as retrievable fields, and keep it attached when assembling context.
A citation should expose the section and evidence depth alongside the source. scrapedAt records acquisition time; it doesn't certify that the seller's description remains current.
An exposé merge is evidence of acquisition
The worked example is Immowelt Germany Rent & Buy Listings Scraper.
Mixed-depth property text is usable when depth survives indexing, retrieval, and citation.
The merge marker establishes an acquisition event. It doesn't certify a complete property inventory, and a longer description doesn't earn that certificate either.
For answer generation, we'd phrase unsupported absence as “not established by the indexed evidence.” A summary can support what it says. Silence isn't a property feature.
Check the boundary in your own index
- Run the input below and inspect the actual merge markers. The cap doesn't promise a mixed corpus when too few listings are emitted or enrichment can't complete.
- Apply the cells in order, then index
jsonlwith its metadata. - Retrieve against both routes. Confirm that summary evidence remains available for discovery and can't enter the exposé route.
- Pass ranked hits through
select_context. Check that citations retain section, depth, source, and scrape timestamp.
Example input for checking whether evidence depth survives your index:
{ "mode": "search", "city": "Berlin", "distributionType": "mieten", "estateType": "wohnung", "includeDetails": true, "maxDetails": 1, "maxItems": 5 } Drafted with AI assistance and reviewed for accuracy.
