Qdrant
Qdrant is a vector similarity search engine. It provides a production-ready service with a convenient API to store, search, and manage points - vectors with an additional payload. Qdrant is tailored to extended filtering support. It makes it useful for all sorts of neural network or semantic-based matching, faceted search, and other applications.
Import all required packages
We start by importing all our required packages. Here is how you do that for python
Define all the constants
After this we define our constants. For Prem, we are required to set our project_id
and embedding_model
. You can learn more about how to get your project_id
and API Key from here.
From Qdrant’s side, we need to also define our server URL, in which we will be sending requests to do all sorts of CRUD operations to our vector database. We also need to define our collection name. You can learn more about these concepts from Qdrant’s quick start guide and concepts.
Last but not the least, we also need to get our documents. For simplicity purpose, we define a small list of documents here. But in actual scenarios, this list should be derived from some source (like database or from an API call etc).
Setup PremAI and Qdrant clients
Once we defined all our constants, it’s time to instantiate Prem AI client and Qdrant client. Heres how you do it in both Python and JavaScript.
Writing a simple helper function to fetch embeddings from documents
Let’s write a simple function to fetch embeddings from document or a list of documents. This process will be done using Prem SDK. We then use this function to embed all our documents, before pushing it to Qdrant’s vector database.
Convert Embeddings to Qdrant Points
Once we are done fetching our embedding vectors with our embedding function, we convert this to Qdrant points. After this, we will use this points to upsert into our Qdrant vector DB collection.
Setting up Qdrant Collection
A collection is a named set of points (vectors with a payload) among which you can search.
If you already have a collection then you can skip this step, otherwise follow the code to create a Qdrant collection. We will be upserting our points in this collection.
Insert Documents to the Collection
Once we have done making our collection, we upload all our document vectors in that collection. Here is how we do that
Searching for documents from a query in a collection
Once our collection is indexed with all our documents, we are now ready to query it and search documents which are semantically similar to the query. Here’s how we do this.
Full code
Congratulations, now you know how you can utilize Prem AI SDK with Qdrant Client to do nearest neighbor search on your documents for your LLM RAG Applications. Here is our starter boilerplate code for both Python and JavaScript.
Was this page helpful?