-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e20f705
commit 64e9e26
Showing
8 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { afterAll, describe, expect, test } from "bun:test"; | ||
import { RangeCommand } from "."; | ||
import { newHttpClient, randomFloat, randomID, resetIndexes } from "../../../utils/test-utils"; | ||
import { UpsertCommand } from "../upsert"; | ||
|
||
const client = newHttpClient(); | ||
|
||
describe("RANGE", () => { | ||
afterAll(async () => await resetIndexes()); | ||
|
||
test("should query records successfully", async () => { | ||
const randomizedData = new Array(20) | ||
.fill("") | ||
.map(() => ({ id: randomID(), vector: [randomFloat(), randomFloat()] })); | ||
|
||
const payloads = randomizedData.map((data) => new UpsertCommand(data).exec(client)); | ||
await Promise.all(payloads); | ||
|
||
const res = await new RangeCommand({ | ||
cursor: 0, | ||
limit: 5, | ||
includeVectors: true, | ||
}).exec(client); | ||
expect(res.nextCursor).toBe("5"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Command } from "../../index"; | ||
import { Vector } from "../types"; | ||
|
||
type Payload = { | ||
cursor: number; | ||
limit: number; | ||
includeVectors?: boolean; | ||
includeMetadata?: boolean; | ||
}; | ||
|
||
type RangeReturnResponse<TMetadata> = { | ||
nextCursor: string; | ||
vectors: Vector<TMetadata>[]; | ||
}; | ||
|
||
export class RangeCommand<TResult> extends Command<RangeReturnResponse<TResult>> { | ||
constructor(payload: Payload) { | ||
super(payload, "range"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Vector<TMetadata> = { | ||
id: string; | ||
vector: number[]; | ||
metadata?: TMetadata; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters