Skip to content

Commit 158ad26

Browse files
authored
CTX7-3252: Type the shared rerank rank on SDK search snippets (#3477)
1 parent c7f80ce commit 158ad26

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎.changeset/sdk-search-rank.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@upstash/context7-sdk": minor
3+
---
4+
5+
`search()` JSON results now type the `rank` field on each code and info snippet: the snippet's 1-based place in the reranked order shared by both lists. Sort `codeSnippets` and `infoSnippets` together by `rank` to read the results in the order the text response gives them.

‎packages/sdk/src/commands/search/index.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("SearchCommand", () => {
1414
codeLanguage: "tsx",
1515
codeList: [{ language: "tsx", code: "const [value] = useState(0);" }],
1616
codeId: "hooks/use-state",
17+
rank: 2,
1718
},
1819
],
1920
infoSnippets: [
@@ -22,6 +23,7 @@ describe("SearchCommand", () => {
2223
breadcrumb: "Hooks > State",
2324
content: "State is local to a component instance.",
2425
pageId: "hooks/state",
26+
rank: 1,
2527
},
2628
],
2729
rules: {

‎packages/sdk/src/commands/types.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,21 @@ export interface Documentation {
7878
export interface SearchCodeSnippet extends ApiCodeSnippet {
7979
/** Context7 library ID that produced this snippet */
8080
libraryId: string;
81+
/**
82+
* 1-based position in the reranked order shared by `codeSnippets` and `infoSnippets`.
83+
* Sort both lists together by `rank` to read the results in the order the text response gives them.
84+
*/
85+
rank: number;
8186
}
8287

8388
export interface SearchInfoSnippet extends ApiInfoSnippet {
8489
/** Context7 library ID that produced this snippet */
8590
libraryId: string;
91+
/**
92+
* 1-based position in the reranked order shared by `codeSnippets` and `infoSnippets`.
93+
* Sort both lists together by `rank` to read the results in the order the text response gives them.
94+
*/
95+
rank: number;
8696
}
8797

8898
export interface SearchResponse {

0 commit comments

Comments
 (0)