Semantic Search & Hybrid Search
Implement advanced search techniques combining vector similarity with keyword matching for superior results.
Beyond Basic Searches
Welcome! In this lesson, we'll dive into advanced search techniques in Weaviate. Moving past simple vector searches, we'll explore how to combine different methods for incredibly precise results.
We'll cover:
- Pure semantic search
- Traditional keyword (BM25) search
- The power of hybrid search
Semantic Search: Meaning First
Semantic search finds items based on their meaning, not just exact words. It uses vector embeddings to represent data, measuring "distance" to find similar concepts. Weaviate uses .with_near_text() for this.
Try this example:
import weaviate
import os
# Connect to your Weaviate instance
# Ensure WEAVIATE_URL is set (e.g., "http://localhost:8080")
client = weaviate.Client(
url=os.getenv("WEAVIATE_URL", "http://localhost:8080")
)
# Make sure you have an 'Article' class with 'title' and 'content' properties
# and some data imported for this to work!
query_concept = "latest advancements in technology"
response = client.query.get(
"Article", # Your class name
["title", "content"]
).with_near_text(
{"concepts": [query_concept]}
).with_limit(2).do()
print("Semantic Search Results:")
for item in response["data"]["Get"]["Article"]:
print(f"- {item['title']}")All lessons in this course
- Semantic Search & Hybrid Search
- Using Weaviate Modules
- Backup and Restore Strategies
- Multi-Tenancy in Weaviate