# How can we make hybrid search results more predictable?

**URL:** <https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893>\
**Category:** Support\
**Created:** [October 31, 2023, 11:54am UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893 "2023-10-31T11:54:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![junbetterway](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/junbetterway/32/174_2.png) [@junbetterway](https://forum.weaviate.io/u/junbetterway)\
**Post date:** [October 31, 2023, 11:54am UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/1 "2023-10-31T11:54:37Z")

</div>

I have a user requirement where we have a **Profile** model which has the following information (all are being saved in Weaviate):

- Full Name
- Marketing pitch (free-text) **→ vectorized**
- Experience story (free-text) **→ vectorized**
- List of tech skills (array) **→ vectorized**
- List of languages (array)
- Other properties, so on

The pitch, story and tech skills are the only ones we are vectorizing as our vectorizer is limited to 250 tokens.

So question, are we right that if we perform a hybrid search even though **languages** or _other properties_ are not vectorized but being saved in Weaviate then it should contribute to the BM25 scoring, right? The results is somehow not matching our expectation. We are using the default **alpha=0.5** (so 50-50 keyword vs vector)

Also, is there a way we can give a high score to the matching full name as our client wants to be able to search by full name as priority. If not, is there like a recommended way to achieve this?

---

<div class="post-metadata">

**Author:** ![sebawita](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/sebawita/32/5_2.png) [@sebawita](https://forum.weaviate.io/u/sebawita)\
**Post date:** [November 1, 2023, 11:55pm UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/2 "2023-11-01T23:55:41Z")

</div>

Hi @junbetterway,

There are many topics to unpack from your post 😉

### Full Name - importance

> [@junbetterway](#):
>
> is there a way we can give a high score to the matching full name

Let’s start with giving the `full name` property more importance.

bm25, and hybrid search offers a mechanism to boost matching on specific properties. We do that by adding `^2`, `^3`, etc to the list of hybrid properties. Where `^2` doubles the importance, while `^3` triples the importance.

Here is an example query in Python:

```python
response = (
    client.query
    .get("MyCollection", ["full_name", "marketing_pitch", "some_other_prop"])
    .with_hybrid(
        query="Jon Doe doing something",
        properties=["full_name^2", "marketing_pitch"],
        alpha=0.5
    )
    .do()
)

```

You can see examples in other languages in the [docs](https://weaviate.io/developers/weaviate/search/hybrid#weight-boost-searched-properties).

Alternatively, if you just want to make sure that the `full_name` is always matched. You could add a filter to the query. Note, only objects that match the filter will be returned. So, only use it when you **must** match the full\_name.  
For example, you could use `Equals` or `Like` operators (see the [docs](https://weaviate.io/developers/weaviate/search/filters#by-partial-matches-text) for more info).  
Like this:

```python
response = (
    client.query
    .get("MyCollection", ["full_name", "marketing_pitch", "some_other_prop"])
    .with_hybrid(
        query="doing something",
        properties=["marketing_pitch", "some_other_prop"],
        alpha=0.5
    )
    .with_where({
        "path": ["full_name"],
        "operator": "Like",
        "valueText": "*Jon Doe*"
    })
    .do()
)

```

### Running Hybrid search on not vectorized properties

> [@junbetterway](#):
>
> So question, are we right that if we perform a hybrid search even though **languages** or _other properties_ are not vectorized but being saved in Weaviate

Yes, you can use the keyword part of the hybrid search on any text property in the database. The properties don’t need to be vectorized.

Also, as you define the data scheme, you can specify the type of tokenization per property.  
Unfortunately, I am not an expert on the topic, but you can learn more [here](https://weaviate.io/developers/weaviate/config-refs/schema#property-tokenization).

---

<div class="post-metadata">

**Author:** ![sebawita](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/sebawita/32/5_2.png) [@sebawita](https://forum.weaviate.io/u/sebawita)\
**Post date:** [November 2, 2023, 12:11am UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/3 "2023-11-02T00:11:28Z")

</div>

> [@junbetterway](#):
>
> The pitch, story and tech skills are the only ones we are vectorizing as our vectorizer is limited to 250 tokens.

What vectorizer do you use?  
Do you generate vector embeddings outside of Weaviate, or do you use one of the Weaviate modules?

It would be great if you could share your Schema configuration.

> [@junbetterway](#):
>
> even though **languages**

What do you mean by “through languages”?  
Are you running queries in different language from the language of the text? i.e. your content is in German, and the query is in English?

If yes, then the keyword part of the query will most likely not work for words that are in different language. However, depending on the ML Model you use (vectorizer), you should be able to match results in other languages.

> note, I’ve used Cohere’s models for multi-lingual search, and I was quite happy with the results. Here is a [small recipe](https://github.com/weaviate/recipes/blob/main/hybrid-search/hybrid_search_cohere.ipynb) that shows end-to-end how to use it.

---

<div class="post-metadata">

**Author:** ![junbetterway](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/junbetterway/32/174_2.png) [@junbetterway](https://forum.weaviate.io/u/junbetterway)\
**Post date:** [November 2, 2023, 1:59am UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/4 "2023-11-02T01:59:55Z")

</div>

Hi @sebawita - thank you for taking time and giving me light on this path 🤘  
Agreed, it has a lot of questions but you managed to give path forward to each - so thank you so much!

Please see below my replies (some follow-up question 🙇‍♂️).

### Full Name - importance

Thank you so much on this - I wonder how I missed this [Weight-boost capability in BM25](https://weaviate.io/developers/weaviate/search/hybrid#weight-boost-searched-properties) when I first implemented the Hybrid search.

Just a qq though, so if do this - I need now to declare all my targeted properties for keyword search - right?

`properties=["full_name^2", "marketing_pitch", "xxx", "yyy", "zzz", so on]`

there is no way to just say, boost the **full\_name** in BM25 search but still include the rest? If not, I am still ok with this and will try to start checking this out in a couple of days.

Also, if I do something like below where I only wanted to declare all the non-vectorized props and boost full name only:

```auto
response = (
    client.query
    .get("MyCollection", ["full_name", "marketing_pitch", "some_other_prop"])
    .with_hybrid(
        query="Jon Doe doing something",
        properties=["full_name^2", "languages", "...other non-vectorized props"],
        alpha=0.5
    )
    .do()
)

```

will the vector search of the hybrid still work on my vectorized props even if they are not declared under **properties** (e.g., marketing\_pitch, exp story) ?

### Running Hybrid search on not vectorized properties

Thanks for confirming this.

Regarding the tokenization method, we are using the default **“word”** so it should work with search strings as shown here [Tokenization and Search Filtering](https://weaviate.io/developers/weaviate/config-refs/schema#tokenization-and-search--filtering) but I think because I am using hybrid with alpha=0.5 so somehow the vector scoring affects the result but will try it out once I played around with the boost props.

### What vectorizer do you use?

We are using the Weaviate module: [text2vec-transformers](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-transformers) where we use the pre-built image:

_semitechnologies/transformers-inference:sentence-transformers-multi-qa-MiniLM-L6-cos-v1_

To your knowledge, is there any recommendation to use for higher tokens (\>250) which is part of Weaviate pre-built images?

### What do you mean by “through languages”?

Sorry for the confusion, but this is just in our **Profile** model - this is just a collection of languages that our users can speak so it has nothing to do with multi-language searching - we are just using English in our platform for now.

I just gave this as an example that this field **languages[]** is not vectorized but will searching it be part of the hybrid search? It is of type **text[]** and not **text** type - will it still be part of the hybrid search?

* * *

Thank you!

---

<div class="post-metadata">

**Author:** ![sebawita](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/sebawita/32/5_2.png) [@sebawita](https://forum.weaviate.io/u/sebawita)\
**Post date:** [November 2, 2023, 11:31pm UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/5 "2023-11-02T23:31:16Z")

</div>

### List of properties for keyword search

> [@junbetterway](#):
>
> Just a qq though, so if do this - I need now to declare all my targeted properties for keyword search - right?
> 
> `properties=["full_name^2", "marketing_pitch", "xxx", "yyy", "zzz", so on]`
> 
> there is no way to just say, boost the **full\_name** in BM25 search but still include the rest?

That is correct, the moment you add `properties` inside `with_hybrid()` you need to list all properties you want to use for the keyword search part of the query.  
If you only list `full_name` (like below), then only `full_name` will be used.

```auto
properties=["full_name^2"]

```

### Properties vs vector search

> [@junbetterway](#):
>
> will the vector search of the hybrid still work on my vectorized props even if they are not declared under **properties** (e.g., marketing\_pitch, exp story) ?

That is correct, the list of `properties` doesn’t affect the vector search part of the query. (it only affects the keyword search).

### Other questions

I need to check with the team, as I don’t use text2vec-transformers much, and need to check about `text[]` properties with hybrid.

---

<div class="post-metadata">

**Author:** ![junbetterway](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/junbetterway/32/174_2.png) [@junbetterway](https://forum.weaviate.io/u/junbetterway)\
**Post date:** [November 3, 2023, 12:57am UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/6 "2023-11-03T00:57:13Z")

</div>

### Properties (keyword) vs vector search

Thanks for confirming this properties vs vector search behavior. I will give this a try then and let you know hopefully, next week 🤞

### Other questions

Thank you!

> I need to check with the team, as I don’t use text2vec-transformers much, and need to check about `text[]` properties with hybrid.

---

<div class="post-metadata">

**Author:** ![jphwang](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/jphwang/32/38_2.png) [@jphwang](https://forum.weaviate.io/u/jphwang)\
**Post date:** [November 3, 2023, 6:24pm UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/7 "2023-11-03T18:24:16Z")

</div>

Hi @junbetterway - I believe the T5 models (like `google/flan-t5-base` see the [list here](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-transformers#option-1-pre-built-images)) can accept 512 tokens, or even longer, according to this discussion:

> <https://github.com/huggingface/transformers/issues/5204>
>
> As the paper described, T5 uses a relative attention mechanism and the answer fo…r this \[issue\](https://github.com/google-research/text-to-text-transfer-transformer/issues/273) says, T5 can use any sequence length were the only constraint is memory. 
> 
> According to this, can I use T5 to summarize inputs that have more than 512 tokens in a sequence?

I don’t think we have a specific one that we recommend.

I hope that helps!

JP

---

<div class="post-metadata">

**Author:** ![sebawita](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/sebawita/32/5_2.png) [@sebawita](https://forum.weaviate.io/u/sebawita)\
**Post date:** [November 3, 2023, 6:39pm UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/8 "2023-11-03T18:39:16Z")

</div>

> [@junbetterway](#):
>
> ### What do you mean by “through languages”?
> 
> Sorry for the confusion, but this is just in our **Profile** model - this is just a collection of languages that our users can speak so it has nothing to do with multi-language searching - we are just using English in our platform for now.
> 
> I just gave this as an example that this field **languages[]** is not vectorized but will searching it be part of the hybrid search? It is of type **text[]** and not **text** type - will it still be part of the hybrid search?

Yes, text arrays should be supported by hybrid and bm25

---

<div class="post-metadata">

**Author:** ![junbetterway](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/junbetterway/32/174_2.png) [@junbetterway](https://forum.weaviate.io/u/junbetterway)\
**Post date:** [November 4, 2023, 12:31am UTC](https://forum.weaviate.io/t/how-can-we-make-hybrid-search-results-more-predictable/893/9 "2023-11-04T00:31:19Z")

</div>

Great thanks @sebawita @jphwang - thanks to both of you specially to @sebawita for answering this question.

We can consider this solved/closed 🙂

I will just post a new question (and try to be more specific) if I hit some bumps along the road. Cheers!
