# Hybrid Search
[Understanding hybrid search](https://docs.pinecone.io/docs/hybrid-search)
Hybrid search combines semantic and keyword search in one query for more relevant results.
## Sparse-dense vectors
Sparse-dense vectors combine [dense and sparse embeddings](https://www.pinecone.io/learn/dense-vector-embeddings-nlp/#dense-vs-sparse-vectors) as a single vector.
[Dense vs Sparse Vectors | Dense Vectors: Capturing Meaning with Code | Pinecone](https://www.pinecone.io/learn/series/nlp/dense-vector-embeddings-nlp/#dense-vs-sparse-vectors)
### Dense vectors
> [!note] dense vectors = 密ベクトル
- the basic vector type in Pinecone
- dense vectors generated by embedding models
- [sentence-transformers (Sentence Transformers)](https://huggingface.co/sentence-transformers)
- numerical representations of semantic meaning
### Sparse vectors
> [!note] sparse vectors = 疎ベクトル
- sparse vectors have very large number of dimensions
- for keywords search
- each sparse vector represents a document
- the dimensions represent words from a dictionary
- the values represent the importance of these words in the document
- compute the relevance of text documents
- based on the number of keyword matches, their frequency, and other factor
- keyword search algorithms
- [Okapi BM25 - Wikipedia](https://en.wikipedia.org/wiki/Okapi_BM25)
## Sparse-dense workflow
1. Create dense vectors using an external embedding model.
2. Create sparse vectors using an external model.
3. Create an index that supports sparse-dense vectors (s1 or p1 with the `dotproduct` metric).
4. Upsert dense and sparse vectors to your index.
5. Search the index using sparse-dense vectors.
6. Pinecone returns sparse-dense vectors.
## Creating sparse vector embeddings
Because Pinecone allows you to create your own sparse vectors, you can use sparse-dense queries to solve the Maximum Inner Product Search (MIPS) problem for sparse-dense vectors of any real values.
[Maximum inner-product search - Wikipedia](https://en.wikipedia.org/wiki/Maximum_inner-product_search)
**Maximum inner-product search** (**MIPS**) is a [search problem](https://en.wikipedia.org/wiki/Search_problem "Search problem"), with a corresponding class of [search algorithms](https://en.wikipedia.org/wiki/Search_algorithm "Search algorithm") which attempt to maximise the [inner product](https://en.wikipedia.org/wiki/Inner_product_space "Inner product space") between a query and the data items to be retrieved.
> [!note] inner product = 内積
- examples of sparse vector generation
- [SPLADE for Sparse Vector Search Explained](https://www.pinecone.io/learn/splade/)
- [SPLADE generation notebook](https://colab.research.google.com/github/pinecone-io/examples/blob/master/pinecone/sparse/splade/splade-vector-generation.ipynb)
- [BM25 generation notebook](https://colab.research.google.com/github/pinecone-io/examples/blob/master/pinecone/sparse/bm25/bm25-vector-generation.ipynb).
## Creating sparse-dense vectors
When you upsert records with sparse and dense vector values, Pinecone creates sparse-dense vectors from your sparse and dense embeddings.
Pinecone does not support vectors with only sparse values.
[Hybrid search and sparse vectors](https://docs.pinecone.io/docs/upserting-sparse-dense-records)
## Querying sparse-dense vectors
[Weighting sparse and dense vectors](https://docs.pinecone.io/docs/weighting-sparse-and-dense-vectors)
## Limitations
- Pinecone supports sparse vector values of sizes up to 1000 non-zero values.
- Pinecone only supports upserting sparse-dense vectors to `p1` and `s1` indexes.
- In order to query an index using sparse values, the index must use the [`dotproduct` metric](https://docs.pinecone.io/docs/indexes#distance-metrics). Attempting to query any other index with sparse values returns an error.
- Indexes created before February 22, 2023 do not support sparse values.
## Example
### Hybrid Search for E-Commerce with Pinecone
By combining the strengths of traditional text-based search algorithms with the visual recognition capabilities of deep learning models, hybrid vector search allows users to search for products using a combination of text and images.
- [ecommerce-search.ipynb](https://github.com/pinecone-io/examples/blob/master/learn/search/hybrid-search/ecommerce-search/ecommerce-search.ipynb)
- [ecommerce-search.ipynb - Colaboratory](https://colab.research.google.com/drive/1TDUh0oXgfuvTb36WeTuhg9Yvid6tyZ-X?usp=sharing)
- sparse vectors
- BM25
- `from pinecone_text.sparse import BM25Encoder`
- [GitHub - pinecone-io/pinecone-text: Pinecone text client library](https://github.com/pinecone-io/pinecone-text)
- dense vectors
- CLIP
- for images
- `from sentence_transformers import SentenceTransformer`
- `sentence-transformers/clip-ViT-B-32`