Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.

Commit bb812af

Browse files
kacperlukawskiJerry Liu
andauthored
Integrate Qdrant as another vector store (run-llama#339)
Co-authored-by: Jerry Liu <jerry@robustintelligence.com>
1 parent 059a19f commit bb812af

File tree

18 files changed

+923
-4
lines changed

18 files changed

+923
-4
lines changed
170 KB
Loading
54.3 KB
Loading

docs/how_to/data_connectors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ All readers can be imported through `from gpt_index.readers import ...`. A subse
2727

2828
See [How to use Vector Stores with GPT Index](vector_stores.md) for a more thorough guide on integrating vector stores with GPT Index.
2929

30+
- Qdrant (`QdrantReader`)
3031
- Weaviate (`WeaviateReader`)
3132
- Pinecone (`PineconeReader`)
3233
- Faiss (`FaissReader`)

docs/how_to/vector_stores.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GPT Index offers multiple integration points with vector stores / vector databas
99
## Loading Data from Vector Stores using Data Connector
1010
GPT Index supports loading data from the following sources. See [Data Connectors](data_connectors.md) for more details and API documentation.
1111

12+
- Qdrant (`QdrantReader`) [Installation](https://qdrant.tech/documentation/install/) [Python Client](https://qdrant.tech/documentation/install/#python-client)
1213
- Weaviate (`WeaviateReader`). [Installation](https://weaviate.io/developers/weaviate/current/getting-started/installation.html). [Python Client](https://weaviate.io/developers/weaviate/current/client-libraries/python.html).
1314
- Pinecone (`PineconeReader`). [Installation/Quickstart](https://docs.pinecone.io/docs/quickstart).
1415
- Faiss (`FaissReader`). [Installation](https://github.com/facebookresearch/faiss/blob/main/INSTALL.md).
@@ -19,6 +20,9 @@ For instance, this is an example usage of the Pinecone data loader `PineconeRead
1920

2021
![](/_static/vector_stores/pinecone_reader.png)
2122

23+
Qdrant stores both documents and vectors, so there is no need to provide `id_to_text_map`. This is an example of how to use it:
24+
25+
![](/_static/vector_stores/qdrant_reader.png)
2226

2327
NOTE: Since Weaviate can store a hybrid of document and vector objects, the user may either choose to explicitly specify `class_name` and `properties` in order to query documents, or they may choose to specify a raw GraphQL query. See below for usage.
2428

@@ -37,6 +41,7 @@ These are found in the following classes:
3741
- `GPTFaissIndex`
3842
- `GPTWeaviateIndex`
3943
- `GPTPineconeIndex`
44+
- `GPTQdrantIndex`
4045

4146
Similar to any other index within GPT Index (tree, keyword table, list), this index can be constructed upon any collection
4247
of documents. We use the vector store within the index to store embeddings for the input text chunks.
@@ -56,4 +61,7 @@ Once constructed, the index can be used for querying.
5661
**Pinecone Index Construction/Querying**
5762
![](/_static/vector_stores/pinecone_index_0.png)
5863

64+
**Qdrant Index Construction/Querying**
65+
![](/_static/vector_stores/qdrant_index_0.png)
66+
5967
[Example notebooks can be found here](https://github.com/jerryjliu/gpt_index/tree/main/examples/vector_indices).
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "f3ca56f0-6ef1-426f-bac5-fd7c374d0f51",
6+
"metadata": {},
7+
"source": [
8+
"# Qdrant Demo"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "262f990a-79c8-413a-9f3c-cd9a3c191307",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"from gpt_index.readers.qdrant import QdrantReader"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"id": "252f8163-7297-44b6-a838-709e9662f3d6",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"reader = QdrantReader(host=\"localhost\")"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"id": "53b49187-8477-436c-9718-5d2f8cc6fad0",
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"# the query_vector is an embedding representation of your query_vector\n",
39+
"# Example query vector:\n",
40+
"# query_vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]\n",
41+
"\n",
42+
"query_vector=[n1, n2, n3, ...]"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"id": "a88be1c4-603f-48b9-ac64-10a219af4951",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"# NOTE: Required args are collection_name, query_vector.\n",
53+
"# See the Python client: https://github.com/qdrant/qdrant_client\n",
54+
"# for more details. \n",
55+
"documents = reader.load_data(collection_name=\"demo\", query_vector=query_vector, limit=5)"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"id": "169b4273-eb20-4d06-9ffe-71320f4570f6",
61+
"metadata": {},
62+
"source": [
63+
"### Create index"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"id": "ac4563a1",
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"index = GPTListIndex(documents)"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": null,
79+
"id": "f06b02db",
80+
"metadata": {},
81+
"outputs": [],
82+
"source": [
83+
"response = index.query(\"<query_text>\", verbose=True)"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"id": "97d1ae80",
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"display(Markdown(f\"<b>{response}</b>\"))"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "Python 3 (ipykernel)",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.9.16"
114+
}
115+
},
116+
"nbformat": 4,
117+
"nbformat_minor": 5
118+
}

0 commit comments

Comments
 (0)