How to use string data to empower your similarity search applications?

Use string data to streamline the process of building your own similarity search applications.

How to use string data to empower your similarity search applications?
How to use string data to empower your similarity search applications?

What can you do with string data?

How to manage string data in Milvus 2.1?

Create a collection

from pymilvus import CollectionSchema, FieldSchema, DataType
book_id = FieldSchema(
name="book_id",
dtype=DataType.INT64,
)
book_name = FieldSchema(
name="book_name",
dtype=DataType.VARCHAR,
max_length=200,
is_primary=True,
)
word_count = FieldSchema(
name="word_count",
dtype=DataType.INT64,
)
book_intro = FieldSchema(
name="book_intro",
dtype=DataType.FLOAT_VECTOR,
dim=2
)
schema = CollectionSchema(
fields=[book_id, word_count, book_intro],
description="Test book search"
)
collection_name = "book"

Insert data

import random
data = [
[i for i in range(2000)],
["book_" + str(i) for i in range(2000)],
[i for i in range(10000, 12000)],
[[random.random() for _ in range(2)] for _ in range(2000)],
]

Delete data

expr = "book_name in [\"book_0\", \"book_1\"]" 
from pymilvus import Collection
collection = Collection("book")
collection.delete(expr)

Build an Index

from pymilvus import Collection
collection = Collection("book")
collection.create_index(
field_name="book_name",
index_name="scalar_index",
)

Hybrid search

search_param = {
"data": [[0.1, 0.2]],
"anns_field": "book_intro",
"param": {"metric_type": "L2", "params": {"nprobe": 10}},
"limit": 2,
"expr": "book_name like \"Hello%\"",
}
res = collection.search(**search_param)

String expressions

Set operations

Compare two string fields

Compare a field with a constant value

Filter fields with a single range

Prefix matching

What’s next

--

--

Scalable similarity search on unstructured data (such as image, video, and natural language) powered by https://milvus.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Milvus

Open-source Vector Database Powering AI Applications. #SimilaritySearch #Embeddings #MachineLearning