Skip to content

[SYNPY-1893] Add search index tutorial - #1447

Draft
thomasyu888 wants to merge 1 commit into
developfrom
SYNPY-1893-search-index-tutorial
Draft

[SYNPY-1893] Add search index tutorial#1447
thomasyu888 wants to merge 1 commit into
developfrom
SYNPY-1893-search-index-tutorial

Conversation

@thomasyu888

@thomasyu888 thomasyu888 commented Aug 17, 2026

Copy link
Copy Markdown
Member

Problem:

No search index tutorial

Solution:

Added tutorial

Testing:

NA yet - will post link to the built documentation per branch

Comment on lines +128 to +149
def wait_for_index(index: SearchIndex, timeout: int = 600) -> None:
"""Wait until the search index has finished building.

Building the OpenSearch index behind a SearchIndex happens in the background
after `store()` returns. Until that build completes, a query against the
index either raises an error or reports zero hits.
"""
deadline = time.time() + timeout
while time.time() < deadline:
try:
results = index.query(
search_query=SearchQuery(query=Query(match_all={}), size=1),
response_parts=[SearchQueryPart.TOTAL_HITS],
)
if results.total_hits:
print(f"Index {index.id} is queryable with {results.total_hits} rows")
return
except SynapseError:
pass # The index has not been created yet
print("Waiting for the search index to build...")
time.sleep(10)
raise TimeoutError(f"{index.id} did not finish building within {timeout} seconds")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is needed. The asynch job and query pattern should be handling for this automatically. The only thing that might be a race condition is the query returning some, but not all results right away (Which this size=1 wouldn't catch)

On the Synapse backend side, even we don't know and we don't wait until all of the individual rows are queryable. The Synapse backend only budgets the time to ensure all of the data is accepted, and then turned on user side querying.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! let me refine this tutorial first, as I haven't had a deep look at any of the claude generated content.

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.

2 participants