mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-16 07:14:29 -04:00
chore: qdrant version updates (#1913)
Co-authored-by: Marcus Schiesser <mail@marcusschiesser.de>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@llamaindex/qdrant": patch
|
||||
---
|
||||
|
||||
Update implementation to use query instead of search which is being deprecated
|
||||
@@ -39,16 +39,16 @@
|
||||
"test": "vitest run"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"vitest": "^2.1.5",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*"
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"vitest": "^2.1.9"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@qdrant/js-client-rest": "^1.11.0"
|
||||
"@qdrant/js-client-rest": "^1.14.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { BaseNode } from "@llamaindex/core/schema";
|
||||
import type { BaseNode, Metadata } from "@llamaindex/core/schema";
|
||||
import {
|
||||
BaseVectorStore,
|
||||
FilterCondition,
|
||||
@@ -18,6 +18,7 @@ import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
type QdrantFilter = Schemas["Filter"];
|
||||
type QdrantMustConditions = QdrantFilter["must"];
|
||||
type QdrantQueryResult = Schemas["QueryResponse"];
|
||||
type QdrantSearchParams = Schemas["SearchParams"];
|
||||
|
||||
type PointStruct = {
|
||||
@@ -34,14 +35,6 @@ type QdrantParams = {
|
||||
batchSize?: number;
|
||||
} & VectorStoreBaseParams;
|
||||
|
||||
type QuerySearchResult = {
|
||||
id: string;
|
||||
score: number;
|
||||
payload: Record<string, unknown>;
|
||||
vector: number[] | null;
|
||||
version: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Qdrant vector store.
|
||||
*/
|
||||
@@ -242,19 +235,19 @@ export class QdrantVectorStore extends BaseVectorStore {
|
||||
* @returns VectorStoreQueryResult
|
||||
*/
|
||||
private parseToQueryResult(
|
||||
response: Array<QuerySearchResult>,
|
||||
response: QdrantQueryResult,
|
||||
): VectorStoreQueryResult {
|
||||
const nodes = [];
|
||||
const similarities = [];
|
||||
const ids = [];
|
||||
const ids: string[] = [];
|
||||
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
const item = response[i]!;
|
||||
const payload = item.payload;
|
||||
for (let i = 0; i < response.points.length; i++) {
|
||||
const item = response.points[i]!;
|
||||
const payload = item.payload as Metadata;
|
||||
|
||||
const node = metadataDictToNode(payload);
|
||||
|
||||
ids.push(item.id);
|
||||
ids.push(item.id.toString());
|
||||
nodes.push(node);
|
||||
similarities.push(item.score);
|
||||
}
|
||||
@@ -304,12 +297,12 @@ export class QdrantVectorStore extends BaseVectorStore {
|
||||
searchParams = buildSearchParams(query);
|
||||
}
|
||||
|
||||
const result = (await this.db.search(this.collectionName, {
|
||||
vector: query.queryEmbedding,
|
||||
const result = (await this.db.query(this.collectionName, {
|
||||
query: query.queryEmbedding,
|
||||
limit: query.similarityTopK,
|
||||
...(queryFilters && { filter: queryFilters }),
|
||||
...(searchParams && { params: searchParams }),
|
||||
})) as Array<QuerySearchResult>;
|
||||
})) as QdrantQueryResult;
|
||||
|
||||
return this.parseToQueryResult(result);
|
||||
}
|
||||
|
||||
@@ -118,14 +118,18 @@ describe("QdrantVectorStore", () => {
|
||||
|
||||
describe("[QdrantVectorStore] search", () => {
|
||||
it("should search in the vector store", async () => {
|
||||
mockQdrantClient.search.mockResolvedValue([
|
||||
{
|
||||
id: "1",
|
||||
score: 0.1,
|
||||
version: 1,
|
||||
payload: { _node_content: JSON.stringify({ text: "hello world" }) },
|
||||
},
|
||||
]);
|
||||
mockQdrantClient.query.mockResolvedValue({
|
||||
points: [
|
||||
{
|
||||
id: "1",
|
||||
score: 0.1,
|
||||
version: 1,
|
||||
payload: {
|
||||
_node_content: JSON.stringify({ text: "hello world" }),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const searchResult = await store.query({
|
||||
queryEmbedding: [0.1, 0.2],
|
||||
@@ -133,7 +137,34 @@ describe("QdrantVectorStore", () => {
|
||||
mode: VectorStoreQueryMode.DEFAULT,
|
||||
});
|
||||
|
||||
expect(mockQdrantClient.search).toHaveBeenCalled();
|
||||
expect(mockQdrantClient.query).toHaveBeenCalled();
|
||||
expect(searchResult.ids).toEqual(["1"]);
|
||||
expect(searchResult.similarities).toEqual([0.1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[QdrantVectorStore] search with id as number", () => {
|
||||
it("should search in the vector store with id as number", async () => {
|
||||
mockQdrantClient.query.mockResolvedValue({
|
||||
points: [
|
||||
{
|
||||
id: 1,
|
||||
score: 0.1,
|
||||
version: 1,
|
||||
payload: {
|
||||
_node_content: JSON.stringify({ text: "hello world" }),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const searchResult = await store.query({
|
||||
queryEmbedding: [0.1, 0.2],
|
||||
similarityTopK: 1,
|
||||
mode: VectorStoreQueryMode.DEFAULT,
|
||||
});
|
||||
|
||||
expect(mockQdrantClient.query).toHaveBeenCalled();
|
||||
expect(searchResult.ids).toEqual(["1"]);
|
||||
expect(searchResult.similarities).toEqual([0.1]);
|
||||
});
|
||||
@@ -141,14 +172,18 @@ describe("QdrantVectorStore", () => {
|
||||
|
||||
describe("[QdrantVectorStore] search with params", () => {
|
||||
it("should search in the vector store", async () => {
|
||||
mockQdrantClient.search.mockResolvedValue([
|
||||
{
|
||||
id: "1",
|
||||
score: 0.1,
|
||||
version: 1,
|
||||
payload: { _node_content: JSON.stringify({ text: "hello world" }) },
|
||||
},
|
||||
]);
|
||||
mockQdrantClient.query.mockResolvedValue({
|
||||
points: [
|
||||
{
|
||||
id: "1",
|
||||
score: 0.1,
|
||||
version: 1,
|
||||
payload: {
|
||||
_node_content: JSON.stringify({ text: "hello world" }),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const searchResult = await store.query(
|
||||
{
|
||||
@@ -163,7 +198,7 @@ describe("QdrantVectorStore", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(mockQdrantClient.search).toHaveBeenCalled();
|
||||
expect(mockQdrantClient.query).toHaveBeenCalled();
|
||||
expect(searchResult.ids).toEqual(["1"]);
|
||||
expect(searchResult.similarities).toEqual([0.1]);
|
||||
});
|
||||
|
||||
Generated
+1252
-78
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user