Skip to main content
1 | © Copyright 8/16/23 Zilliz
1 | © Copyright 8/16/23 Zilliz
Full Text Search with Milvus
2.5
Unstructured Data Meetup | Jan. 23
2 | © Copyright 8/16/23 Zilliz
2 | © Copyright 8/16/23 Zilliz
Stephen Batifol
Developer Advocate, Zilliz / Milvus
About Me
stephen.batifol@zilliz.com
linkedin.com/in/stephen-batifol/
@stephenbtl
3 | © Copyright 8/16/23 Zilliz
3 | © Copyright 8/16/23 Zilliz
● Pip-install on your laptop
● Plug into your favorite AI dev tools
● Push to production with a single line of code
Easy to start
4 | © Copyright 8/16/23 Zilliz
4 | © Copyright 8/16/23 Zilliz
2024
Milvus Lite Milvus Standalone Milvus Distributed
● Ideal for prototyping,
small scale
experiments.
● Easy to set up and
use, pip instally
pymilvus
● Scale to ≈1M vectors
● Run on K8s
● Load balancer and
Multi-Node
Management
● Scaling of each
component
independently
● Scale to 100B
vectors
● Single-Node
Deployment
● Bundled in a single
Docker Image
● Supports Primary/
Secondary
● Scale up to 100M
vectors
Ready to scale 🚀
Write your code once, and run it everywhere, at scale!
● API and SDK are the same
5 | © Copyright 8/16/23 Zilliz
5 | © Copyright 8/16/23 Zilliz
| © Copyright 8/16/23 Zilliz
5
What is Full Text Search?
6 | © Copyright 8/16/23 Zilliz
6 | © Copyright 8/16/23 Zilliz
● Advanced document retrieval based on specific terms
and phrases
● Complements semantic search by catching precise term
matches
● Automatically converts text to sparse embeddings
● Uses BM25 algorithm for intelligent relevance scoring
● Perfect for RAG applications needing precise term
matching
What is Full Text Search?
7 | © Copyright 8/16/23 Zilliz
7 | © Copyright 8/16/23 Zilliz
● Hybrid Search can improve RAG search quality
● Dense Embeddings are impressive but can be limited:
○ Lack of explainability
○ Suboptimal performance with:
■ Long-tail queries
■ Rare terms
● Pure keyword matching (like BM25) sometimes
outperforms sophisticated models in domain-specific
scenarios
Why does it matter?
8 | © Copyright 8/16/23 Zilliz
8 | © Copyright 8/16/23 Zilliz
● Vector search is great for semantic
understanding
○ Can miss exact keyword matches
● Run two separate systems
○ Vector DB for semantic search
○ Elasticsearch/similar for keyword search
Results in complex architecture and
operational overhead
The Search Dilemma
9 | © Copyright 8/16/23 Zilliz
9 | © Copyright 8/16/23 Zilliz
Future of search is combining different search paradigms
1. Semantic Search
2. Keyword Search
3. Filtering
All, in one unified platform
Our Vision is more than just Vectors
10 | © Copyright 8/16/23 Zilliz
10 | © Copyright 8/16/23 Zilliz
10 | © Copyright 8/16/23 Zilliz
10 | © Copyright 8/16/23 Zilliz
Letʼs take a step back
11 | © Copyright 8/16/23 Zilliz
11 | © Copyright 8/16/23 Zilliz
TFIDF
Full Text Search algorithm based on term and doc
weight:
● Term Frequency measures the weight of
document: the more terms it includes, the more
important
● Inverse Document Frequency measures the
weight of terms: the less common it is in the doc
base, the more important
12 | © Copyright 8/16/23 Zilliz
12 | © Copyright 8/16/23 Zilliz
BM25
Improvement over the TFIDF algo
Term Frequency Saturation:
● Prevent words that occurs too frequently from dominating the score
● Document Length Normalization
● Reduces TFIDFʼs bias towards long documents
13 | © Copyright 8/16/23 Zilliz
13 | © Copyright 8/16/23 Zilliz
BM25
● Simple implementation
● Good Retrieval performance
○ Queries Per Second
○ Accuracy
● Used by others in the industry
○ ElasticSearch
○ Apache Lucene
○ MongoDB Atlas Search
○ …
14 | © Copyright 8/16/23 Zilliz
14 | © Copyright 8/16/23 Zilliz
Why do we care about BM25?
We want to:
● Augment the Search Quality of Embedding based
Semantic Search
● Provide Search with more emphasis on Keyword
Matching
● Easy Hybrid Search of BM25  Dense Embeddings
in a single system.
15 | © Copyright 8/16/23 Zilliz
15 | © Copyright 8/16/23 Zilliz
15 | © Copyright 8/16/23 Zilliz
15 | © Copyright 8/16/23 Zilliz
Sparse Vectors
16 | © Copyright 8/16/23 Zilliz
16 | © Copyright 8/16/23 Zilliz
● Super high dimensional vectors with only a few being non-zero.
● Usually represented as a map of {non_zero_dim: actual_value}
Sparse Vectors
17 | © Copyright 8/16/23 Zilliz
17 | © Copyright 8/16/23 Zilliz
Due to the extra high dimensionality, L2 or COSINE will most likely not work due to the
Curse of Dimensionality.
All mass are spread on the surface of the high dimension sphere, all vectors tends to
have a same distance to each other, making kNN meaningless.
Sparse Vectors Metric
18 | © Copyright 8/16/23 Zilliz
18 | © Copyright 8/16/23 Zilliz
18 | © Copyright 8/16/23 Zilliz
18 | © Copyright 8/16/23 Zilliz
Computing BM25 using
Sparse Vectors
19 | © Copyright 8/16/23 Zilliz
19 | © Copyright 8/16/23 Zilliz
Old Approach
1. Get a static statistics of word distribution and document length
2. Encode the document and insert into the database
3. When search, encode the query and rank by IP score.
Problem:
● Statistics are static and once trained cannot be updated as documents being
added/removed.
● The user must manage the statistics themselves from the client side.
⇒ This can be annoying for the user!
20 | © Copyright 8/16/23 Zilliz
20 | © Copyright 8/16/23 Zilliz
Old Approach
Documents / Query
Text Analyzer
Stats Management
Vector DB
Build / Search on Sparse
Vector Index
Hello Milvus
“helloˮ, “milvusˮ
Doc
{
“helloˮ: f(TF),
“milvusˮ: f(TF),
}
Query
{
“helloˮ: IDF,
“milvusˮ: IDF,
}
21 | © Copyright 8/16/23 Zilliz
21 | © Copyright 8/16/23 Zilliz
Old Approach
Documents / Query
Text Analyzer
Stats Management
Vector DB
Build / Search on Sparse
Vector Index
Clientʼs Side
22 | © Copyright 8/16/23 Zilliz
22 | © Copyright 8/16/23 Zilliz
22 | © Copyright 8/16/23 Zilliz
22 | © Copyright 8/16/23 Zilliz
Milvusʼ Approach
23 | © Copyright 8/16/23 Zilliz
23 | © Copyright 8/16/23 Zilliz
Milvusʼ Approach
The user can almost forget about Vectors
● Insert the raw text into Milvus and search using the text.
Milvus takes care of
● Text Analyzing and Tokenization
● Term distribution statistics management
● Document/Query vector encoding
● BM25 based scoring
24 | © Copyright 8/16/23 Zilliz
24 | © Copyright 8/16/23 Zilliz
Milvusʼ Approach
Documents / Query
Text Analyzer
Stats Management
Vector DB
Build / Search on Sparse
Vector Index
Milvus takes care of everything ✨
Users only need to interact with
their raw data
25 | © Copyright 8/16/23 Zilliz
25 | © Copyright 8/16/23 Zilliz
Converts raw text into a structured, searchable format. An analyzer in Milvus
consists of exactly one tokenizer and zero or more filters.
● Tokenizer: The tokenizer breaks input text into discrete units called tokens.
These tokens could be words or phrases, depending on the tokenizer type.
● Filters: Filters can be applied to tokens to further refine them, for example, by
making them lowercase or removing common words.
Powered by Tantivy.
Text Analyzer
26 | © Copyright 8/16/23 Zilliz
26 | © Copyright 8/16/23 Zilliz
Text Analyzer
27 | © Copyright 8/16/23 Zilliz
27 | © Copyright 8/16/23 Zilliz
Built in Analyzer which supports:
● standard: Suitable for general-purpose text processing, applying standard
tokenization and lowercase filtering.
● english: Optimized for English-language text, with support for English stop
words.
● chinese: Specialized for processing Chinese text, including tokenization
adapted for Chinese language structures.
We also support Custom ones → https://milvus.io/docs/analyzer-overview.md
Text Analyzer
28 | © Copyright 8/16/23 Zilliz
28 | © Copyright 8/16/23 Zilliz
Full Text Search
29 | © Copyright 8/16/23 Zilliz
29 | © Copyright 8/16/23 Zilliz
| © Copyright 8/16/23 Zilliz
29
Demo!
30 | © Copyright 8/16/23 Zilliz
30 | © Copyright 8/16/23 Zilliz
The Solution
● Unified system for both vector and keyword search
● Built-in sparse-BM25 algorithm
● No need to manually generate embeddings for
keyword search
31 | © Copyright 8/16/23 Zilliz
31 | © Copyright 8/16/23 Zilliz
The Benefits
● Simple operations
○ Single system to maintain
○ Automatic text analysis and tokenization
○ Simplified data consistency
● Higher search accuracy
○ Better search accuracy through a combined approach
○ Better handling of technical terms
● Better system performance
○ Lower latency with unified querying
32 | © Copyright 8/16/23 Zilliz
32 | © Copyright 8/16/23 Zilliz
milvus.io
github.com/milvus-io/
@milvusio
@stephenbtl
/in/stephen-batifol
Thank you