# Query vector embeddings with semantic search

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/)
- [Understand vector search with Qdrant on Google Axion](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/background/)
- [Create a Google Axion C4A Arm virtual machine](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/instance/)
- [Install and run Qdrant on Axion](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/install-qdrant/)
- [Generate and index vector embeddings](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/ingest-vectors/)
- [Query vector embeddings with semantic search](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/semantic-search/)
- [Build a chatbot with Qdrant on Axion](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/chatbot-usecase/)
- [Understand the vector search architecture](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/architecture/)
- [Next Steps](https://learn.arm.com/learning-paths/servers-and-cloud-computing/qdrant-on-axion/_next-steps/)

## Implement semantic similarity queries
In this section, you query the Qdrant vector database using **semantic similarity search**.

Unlike traditional keyword search, semantic search compares vector embeddings to identify the most relevant results based on **meaning and context** rather than exact keyword matches.

Semantic search enables AI applications such as chatbots, recommendation systems, and knowledge retrieval platforms.

## Architecture overview
The workflow retrieves the most relevant documents using vector similarity.

```
User Query
      |
      v
Sentence Transformer Model
      |
      v
Query Embedding Vector
      |
      v
Qdrant Vector Database
      |
      v
Similarity Search
      |
      v
Top Matching Documents
```

## Create the search script
Navigate to the project directory, then create the Python script used to query the vector database.

```
cd ~/qdrant-rag-demo
vi search.py
```

Add the following code:

```
from qdrant_client import QdrantClient
from sentence_transformers import SentenceTransformer

client = QdrantClient(url="http://localhost:6333")

model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")

query = "What is vector search?"

query_vector = model.encode(query).tolist()

results = client.query_points(
    collection_name="axion_demo",
    query=query_vector,
    limit=2
)

print("\nTop results:\n")

for point in results.points:
    print(point.payload["text"])
```

### What this script does
The script performs the following steps:
- Connects to the Qdrant vector database
- Loads a pretrained transformer embedding model
- Converts the query into a vector embedding
- Performs similarity search against stored vectors
- Returns the most relevant documents

## Run the search script
Execute the search script.

```
python search.py
```

The output is similar to:

```
__output__ Vector databases enable semantic search.
__output__ Qdrant is optimized for vector similarity search.
```

The output confirms that the system successfully retrieved the most semantically relevant documents.

## Why semantic search is powerful
Traditional search engines rely on keyword matching, which often fails when queries are phrased differently.

Semantic search uses vector embeddings to capture meaning.

| User Query                | Retrieved Result                               |
|---------------------------|------------------------------------------------|
| What is vector search?    | Vector databases enable semantic search.      |
| Explain Qdrant            | Qdrant is optimized for vector similarity search. |
| How do embeddings work?   | Vector databases enable semantic search.      |

Semantic search allows applications to understand **intent rather than exact wording**.

## What you’ve learned and what’s next
In this section, you learned how to:
- Convert user queries into vector embeddings
- Query the Qdrant vector database
- Retrieve semantically relevant documents
- Understand how semantic similarity search works

In the next section, you will extend this workflow to build a **chatbot-style knowledge retrieval system**, allowing users to interactively query the vector database using natural language.
