[Question] about Hybrid search

I have an object with vectors and properties, and one of the fields in the properties is a location, and I want to use a hybrid search, where the input is a vector, and I want to find something similar to the vector, and there is also a location string, and I want to find something related to the location, can I use a hybrid search?

Hi @arthur_zhang,

Welcome to the Weaviate Community.

Sure, you can use the location together with you vector query.

You have two options: “filter” and “hybrid”.

Option 1 - filter

You can add a filter condition to any query. In your case, you may want to add a filter that looks for a value in the location property.

Here is a Python example:

from weaviate.classes.query import Filter

cities = client.collections.get("Cities")
response = cities.query.near_text(
    query="your vector query here",
    filters=Filter.by_property("location").like("york"), # will match new york and your
    limit=3
)

Docs for reference: near_text with filter, filter page (note, all filter examples can be used with any type of query).

Option 2 - hybrid

You could also use hybrid search and specify separate queries for the keyword search on “location” and for the vector search.

Normally, the query is used for both the keyword and vector search, but you can also use vector property to define the vector search separately, like this:

from weaviate.classes.query import HybridVector, Move, HybridFusion

jeopardy = client.collections.get("JeopardyQuestion")
response = jeopardy.query.hybrid(
    query="york", # your keyword search here
    query_properties=["location"], # run the keyword search only on location
    vector=HybridVector.near_text(
        query="you vector query goes here",
    ),
    limit=5,
)

Here is a smiliar example in the docs.