Skip to content

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

Open
thomasyu888 wants to merge 10 commits into
developfrom
SYNPY-1893-search-index-tutorial
Open

[SYNPY-1893] Add search index tutorial#1447
thomasyu888 wants to merge 10 commits 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:

https://synapsepythonclient--1447.org.readthedocs.build/en/1447/

Comment thread docs/tutorials/python/tutorial_scripts/search.py Outdated
@thomasyu888
thomasyu888 marked this pull request as ready for review August 21, 2026 04:23
@thomasyu888
thomasyu888 requested a review from a team as a code owner August 21, 2026 04:23
Copilot AI lite review requested due to automatic review settings August 21, 2026 04:23
Comment thread docs/tutorials/python/search.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread docs/tutorials/python/tutorial_scripts/search.py Outdated
Comment thread docs/tutorials/python/tutorial_scripts/search.py


# --8<-- [start:search_configuration]
def create_search_configuration() -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this function used anywhere in the tutorial?

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.

It isn't executed by design, because of the nuance described in the markdown file



# --8<-- [start:apply_search_configuration]
def create_index_with_configuration(search_configuration_id: str) -> SearchIndex:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this function used anywhere in the tutorial?

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.

I'm still thinking whether this "sage only" section should live here or if it should actually live within the "explanations" folder as an "advanced topic" since this isn't "open to the world"

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 would elect to have both. Where the tutorial touches on the concept, but then links to a more in depth explanation that talks about it more

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.

I'll create a ticket for the "advanced topic" for later, but it would be good for samia and I to coordinate on what that looks like

Comment thread docs/tutorials/python/tutorial_scripts/search.py
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",

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.

If it isn't mentioned in the tutorial a not about casing should be included. In all of the synonyms that I created for our portal I lowercase the synonyms inside the SynonymSet. The reason for this is that when this default_search filter pipeline is used it will lowercase the user's search terms before applying synonyms. If the synonyms themselves are not lowercase then it would not match to a synonym and expand it.

Comment thread docs/tutorials/python/search.md Outdated
```
</details>

### Cursor paging with `search_after`

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.

search_after also needs to be used when paginating beyond 10k rows. That was what I recall from the opensearch docs that the offset working right.

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.

Do you think that we should just have the search_after? or is having both pagination and search after critical?

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.

Using just search_after would be better if the framing is "Enumerate every result", but if the framing is I want the 504th result, then offset would be used.

Both can be kept because they are genuinely different use cases

## Advanced: Tune matching with synonyms and analyzers

!!! warning "Restricted and permanent"
Creating and updating the following resources is restricted to Sage Bionetworks employees,

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.

Everything including SearchIndex creation is gated behind the Sage Bio employee restriction

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.

I see, so there's the setup, and then there's the usage. Perhaps I'll shuffle things around so that the setup is first, then the usage of the indexes is second?

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.

Sounds fine to me. The querying part is free to use by everyone whereas the setup is sage only.

@BryanFauble BryanFauble left a comment

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.

There are a few suggested changes to improve this, but I'll approve now because it's shaping up well.

Feel free to ignore the build status on this PR since it isn't affecting anything tested.

Comment on lines +60 to +63
* a [Table][synapseclient.models.Table]
* an [EntityView][synapseclient.models.EntityView]
* a [DatasetCollection][synapseclient.models.DatasetCollection]
* a [MaterializedView][synapseclient.models.MaterializedView]

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.

@BryanFauble Are VirtualTable or Datasets supported?

GET, so ask for the largest `size` you can use rather than walking a big index in small
pages.

## Advanced: Tune matching with synonyms and analyzers

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.

@BryanFauble what does the index.query functions look like in this tutorial if the following is all set up already?

would we still have to fine-tune the query parameters like we do in sections 3,4,5,6,7?

</details>

Hits come back ranked by relevance, and each one carries its score on
[`hit.score`][synapseclient.models.SearchHit] along with the `row_id` and `row_version`

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.

Not returning row_id and row_version, but look at hit score

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.

@BryanFauble how is score determined?

</details>

**Note**: Highlighting, like relevance scoring, depends on the column being indexed as
analyzed text. Step 9 covers how to control that with a

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.

no longer step 9

Comment on lines +169 to +172
* `must` clauses have to match and **do** contribute to the relevance score
* `filter` and `must_not` clauses have to match (or not match) but **do not** affect
the score — use these for hard constraints like a numeric cutoff
* `should` clauses boost the rows that match them without excluding the rows that don't

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.

More explanation of how this is actually working would be great.

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.

4 participants