Skip to content

Context7 Platform -- Up-to-date docs for AI agents

CTX7-3252: Type the shared rerank rank on SDK search snippets (#3477)

Ramazan Onur Acar158ad2626101
diff --git a/.changeset/sdk-search-rank.md b/.changeset/sdk-search-rank.md
new file mode 100644
index 00000000..8afeced8
--- /dev/null
+++ b/.changeset/sdk-search-rank.md
@@ -0,0 +1,5 @@
+---
+"@upstash/context7-sdk": minor
+---
+
+`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.
diff --git a/packages/sdk/src/commands/search/index.test.ts b/packages/sdk/src/commands/search/index.test.ts
index 95721508..22c34bb8 100644
--- a/packages/sdk/src/commands/search/index.test.ts
+++ b/packages/sdk/src/commands/search/index.test.ts
@@ -14,6 +14,7 @@ describe("SearchCommand", () => {
codeLanguage: "tsx",
codeList: [{ language: "tsx", code: "const [value] = useState(0);" }],
codeId: "hooks/use-state",
+ rank: 2,
},
],
infoSnippets: [
@@ -22,6 +23,7 @@ describe("SearchCommand", () => {
breadcrumb: "Hooks > State",
content: "State is local to a component instance.",
pageId: "hooks/state",
+ rank: 1,
},
],
rules: {
diff --git a/packages/sdk/src/commands/types.ts b/packages/sdk/src/commands/types.ts
index 36111a7c..b9666001 100644
--- a/packages/sdk/src/commands/types.ts
+++ b/packages/sdk/src/commands/types.ts
@@ -78,11 +78,21 @@ export interface Documentation {
export interface SearchCodeSnippet extends ApiCodeSnippet {
/** Context7 library ID that produced this snippet */
libraryId: string;
+ /**
+ * 1-based position in the reranked order shared by `codeSnippets` and `infoSnippets`.
+ * Sort both lists together by `rank` to read the results in the order the text response gives them.
+ */
+ rank: number;
}
export interface SearchInfoSnippet extends ApiInfoSnippet {
/** Context7 library ID that produced this snippet */
libraryId: string;
+ /**
+ * 1-based position in the reranked order shared by `codeSnippets` and `infoSnippets`.
+ * Sort both lists together by `rank` to read the results in the order the text response gives them.
+ */
+ rank: number;
}
export interface SearchResponse {