# Similarity search based on multiple text attributes

**URL:** <https://discuss.huggingface.co/t/similarity-search-based-on-multiple-text-attributes/64576>\
**Category:** Intermediate\
**Created:** [December 4, 2023, 8:39pm UTC](https://discuss.huggingface.co/t/similarity-search-based-on-multiple-text-attributes/64576 "2023-12-04T20:39:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jssaluja](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@jssaluja](https://discuss.huggingface.co/u/jssaluja)\
**Post date:** [December 4, 2023, 8:39pm UTC](https://discuss.huggingface.co/t/similarity-search-based-on-multiple-text-attributes/64576/1 "2023-12-04T20:39:31Z")

</div>

Good day experts

I need to build a system to recommend related rows.  
If query = row1, I need results ranked by similarity which combines signal from all attributes.

Each row has multiple text attributes.  
Each of these attribute is a independent document.  
Attribute1 = doc1, Attribute2 = doc2… and so on.

Number of documents per row is variable  
Row 1 may contain Attribute1 = doc1, Attribute 2 = doc2.  
Row 2 may contain Attribute1 = doc1, Attribute 2 = doc2 … Attribute10 = doc10.

I considered two approaches.

1. Concatenate first n characters of each attribute (doc) and get embeddings for one concatenated string
2. Get embeddings for each attribute (doc) separately

Approach 1 saves us cost of fetching and storing embeddings. This requires concatenating chunks from separate documents. I have a concern. This approach may result in a concatenated string with abrupt change in content and semantic meaning at the points of concatenation.

Approach 2 is costly, we need to fetch embeddings for multiple documents per row. However I think, the embeddings are more usable as each document retains its meaning.

Question 1 - Which approach do experts recommend 1 or 2, and why ?  
Question 2 - Any guidance on doing similarity search for embeddings from multiple text attributes ?  
Can we simply concatenate the embeddings ?  
How do we handle rows with different number of attributes ie., different length of concatenated embeddings ?
