Part 2: Populating Your Vector Database – Embedding and Uploading Data

In our previous post, we covered the fundamental concepts of RAG and set up our environment, including our LLM/embedding provider and Qdrant vector database. Now, it's time to prepare our data and store it in a way that allows for efficient semantic search. This involves converting our textual data into embeddings and uploading them to Qdrant.
The Process: From Text to Searchable Vectors
Identify Your Data Source: This is the knowledge base you want your RAG system to draw from. It could be a collection of documents, articles, FAQs, product descriptions, or any textual data. For this tutorial, let's assume you have your content ready as text.
Data Preprocessing (Optional but Recommended): Before embedding, consider preprocessing your text. This might include:
Chunking: Breaking down large documents into smaller, manageable pieces (e.g., paragraphs or sections). This helps in retrieving more focused context.
Cleaning: Removing irrelevant characters, HTML tags, or standardizing text (e.g., lowercasing).
Standardization: As mentioned in the initial ideas, "standardizing" user input (and by extension, your source data) for grammar and meaning can improve search precision. This could involve using an LLM for paraphrasing or grammar correction, though it adds a step and computational cost.
Generating Embeddings: Each piece of text (or chunk) needs to be converted into a numerical vector (embedding) using your chosen embedding model (from Ollama, LMStudio, or Cloudflare).
Here's a conceptual
curl
example of how to get an embedding for a piece of text using an OpenAI-compatible API endpoint (like one provided by Cloudflare Workers AI or a local Ollama setup):curl --request POST \ --url https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/embeddings \ --header 'Authorization: Bearer {api_token}' \ --header 'Content-Type: application/json' \ --data '{ "input": "This is the text I want to embed.", "model": "@cf/baai/bge-base-en-v1.5" }'
# Example output structure { "object": "list", "data": [ { "object": "embedding", "embedding": [ 0.0286865234375, -0.0113525390625, ... -0.003662109375, 0.0290985107421875 ], "index": 0 } ], "model": "@cf/baai/bge-base-en-v1.5" }
Uploading Embeddings and Data to Qdrant: Once you have the embedding (vector) for a piece of text, you need to upload it to your Qdrant collection. Along with the vector, you should also store either the original text itself or an ID that allows you to retrieve the original text later. This associated data is called the "payload" in Qdrant.
Here's a conceptual
curl
example for uploading points (vector + payload) to your Qdrant collection (e.g.,my_rag_collection
):curl -X PUT 'http://localhost:6333/collections/{collection_name}/points?wait=true' \\ -H 'api-key: YOUR_QDRANT_API_KEY' \\ -H 'Content-Type: application/json' \\ -d '{ "points": [ { "id": 1, "vector": [0.0123, -0.0456, ..., 0.0789], "payload": { "text_content": "This is the text I want to embed.", "source": "document_A.txt" } }, { "id": "some-uuid-string-2" "vector": [0.9876, -0.5432, ..., 0.1122], "payload": { "text_content": "Another piece of important information.", "page_number": 5 } } // ... more points ] }'
wait=true
ensures the operation completes before the API returns a response.The
id
for each point should be unique.The
payload
can contain any JSON object. Storing thetext_content
directly is convenient for smaller texts. For larger documents, you might store an ID and fetch the full content from a separate database if needed.
Iteration is Key
You'll iterate through all your data chunks:
Get the text chunk.
Generate its embedding.
Upload the embedding and its associated payload (including the original text or an ID) to Qdrant.
Outcome: By the end of this part, your Qdrant collection will be populated with the vectorized representations of your knowledge base, ready to be queried. In the next post, we'll explore how to take user input, embed it, and search this database for relevant information.
Subscribe to my newsletter
Read articles from Debjit Biswas directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Debjit Biswas
Debjit Biswas
Developer