Live data from Hacker News

Building a semantic search engine in Rust

sachaarbonel.medium.com

21–29 of 29 posts

Re: Building a semantic search engine in Rust

#21
post #9

I remember when "semantic search" was the Next Big Thing (back when all we had were simple keyword searches). I don't know enough about the internals of Google's search engine to know if it could be called a "semantic search engine", but not, it gets close enough to fool me. But I feel like I'm still stuck on keyword searches for a lot of other things, like email (outlook and mutt), grepping IRC logs, searching for p…

Semantic similarity more concretely means to use neural nets to embed the text, then use cosine similarity or dot product to compute the score between two entities. embed1 = neural_net(txt1) embed2 = neural_net(txt2) sim_score = np.dot(embed1, embed2) If you're making a search engine you precompute the embeds for all the items in your database. When a user performs a search you just need to embed the query and do the…

Are there any semantic search implementations focused on.. small, local deploys?

Eg i'm interested in local serverless setups (on desktop, mobile, etc) that yield quality search results in the ~instant~ time frame, but that are also complete and accurate in results. Ie i threw out investigating ANN because i wanted complete results due to smaller datasets.

Re: Building a semantic search engine in Rust

#22
post #9

Earlier quoted context omitted.

Semantic similarity more concretely means to use neural nets to embed the text, then use cosine similarity or dot product to compute the score between two entities. embed1 = neural_net(txt1) embed2 = neural_net(txt2) sim_score = np.dot(embed1, embed2) If you're making a search engine you precompute the embeds for all the items in your database. When a user performs a search you just need to embed the query and do the…

Are there any semantic search implementations focused on.. small, local deploys? Eg i'm interested in local serverless setups (on desktop, mobile, etc) that yield quality search results in the ~instant~ time frame, but that are also complete and accurate in results. Ie i threw out investigating ANN because i wanted complete results due to smaller datasets.

hnswlib is in cpp and has python bindings (you should be able to make your own for other languages). Faiss, Annoy (by Spotify) should also provide similar functionality.

https://github.com/nmslib/hnswlib

Re: Building a semantic search engine in Rust

#23

One of the core problems in semantic search is doing efficient approximate nearest neighbor search. In this post the author uses KD trees. There are other alternatives for efficient ANN like scann from Google and faiss from Facebook.

You're actually comparing a data structure (KD trees) to a library (scann and faiss). HNSW is the data structure that is commonly used by vector search databases. If we're in the Rust world, Qdrant is a great example here.

[deleted]

Re: Building a semantic search engine in Rust

#24
post #18
post #5

But isn’t that PyTorch with a few extra steps?

Yes, it's a well solved problem and much easier to do in Python. The author just wanted to do it in Rust, that's all.

sure, my point was more that it uses pytorch -> also lots of c++ :-)

Re: Building a semantic search engine in Rust

#25

I remember when "semantic search" was the Next Big Thing (back when all we had were simple keyword searches). I don't know enough about the internals of Google's search engine to know if it could be called a "semantic search engine", but not, it gets close enough to fool me. But I feel like I'm still stuck on keyword searches for a lot of other things, like email (outlook and mutt), grepping IRC logs, searching for p…

This is an area that's dear to me, I'm the cofounder of Vectara and have been working with embedding-based semantic search, aka neural search or neural IR, since 2017.

To whether Google uses semantic search, the answer is yes, very heavily [1][2]. Not only that, but they have led, and continue to lead, much of the pioneering research in NLP and neural IR for the past decade [3][4][5].

Technical challenges lie along a few primary dimensions. The first has been search quality, because, while early neural systems like Google Talk to Books [5][6] demonstrated the potential of these techniques, benchmarks like BEIR [7], released a few years later, in 2020, showed that the best keyword retrieval algorithms still outperformed neural techniques in general settings.

The landscape since then has shifted very rapidly: In 2022, for the first time, neural search methods outperformed BM25 on BEIR. This includes late interaction [8], sparse encoding [9], and, most challengingly, dense encoding [10] systems.

The second technical challenge is scalability. After decades of infrastructure optimization, keyword systems scale well to very large corpora, while semantic systems struggle to achieve the same scale. The k-d tree approach presented in the article, for example, while good for experimentation, would be difficult to productionize, as-is, in a large-scale system.

However, research into scaling dense vector retrieval has received a lot of focus recently [11], so I'm confident this will change.

I'll close by saying your observation about being stuck with keyword search in a lot of apps is accurate, but I expect that to change soon. It's becoming easier to embed neural models everywhere, and I think that distilled models in the 5-50mb size range can feasibly power semantic search everywhere you press Ctrl-F today.

[1] https://blog.google/products/search/search-language-understa...

[2] https://blog.google/products/search/introducing-mum/

[2] https://arxiv.org/abs/1706.03762

[3] https://arxiv.org/abs/1810.04805

[4] https://arxiv.org/abs/1907.04307

[5] https://books.google.com/talktobooks/

[6] https://ai.googleblog.com/2018/04/introducing-semantic-exper...

[7] https://arxiv.org/abs/2104.08663

[8] https://arxiv.org/abs/2112.01488

[9] https://arxiv.org/abs/2109.10086

[10] https://arxiv.org/pdf/2112.09118.pdf

[11] https://www.microsoft.com/en-us/research/uploads/prod/2021/1...

Re: Building a semantic search engine in Rust

#26

Earlier quoted context omitted.

That doesn't explain why Atlassian can't build a working search function for Confluence. I get the feeling the biggest problem with site-local search engines is a tacit requirement that the search index always must be up to date. That severely hamstrings any search engine, since there's a wealth of supplemental information to be gathered by considering the corpus as a whole that is simply not available if you support…

Generally not a fan of Atlassian, but I can't say Confluence search has been a problem, I have more problems searching within Google Workspace (if its still called that this week).

I'm not particularly impressed by it.

It's made worse by the fact that it's usually the only way of navigating confluence, as any non-trivial confluence eventually turns into a nightmare maze of abandoned stale pages, dead links and half-baked attempts at restructuring it where the person enthusiastically pushing for the restructuring effort sort of gave up a third through because it turned out to be a lot more work than it seemed.

I've seen this time and time again in both big and small organizations that use confluence. Makes me feel there is a fundamental design problem with the product.

Re: Building a semantic search engine in Rust

#27
post #9

I remember when "semantic search" was the Next Big Thing (back when all we had were simple keyword searches). I don't know enough about the internals of Google's search engine to know if it could be called a "semantic search engine", but not, it gets close enough to fool me. But I feel like I'm still stuck on keyword searches for a lot of other things, like email (outlook and mutt), grepping IRC logs, searching for p…

Semantic similarity more concretely means to use neural nets to embed the text, then use cosine similarity or dot product to compute the score between two entities. embed1 = neural_net(txt1) embed2 = neural_net(txt2) sim_score = np.dot(embed1, embed2) If you're making a search engine you precompute the embeds for all the items in your database. When a user performs a search you just need to embed the query and do the…

For anybody interested in why this comment says "cosine similarity _or_ dot product", its because the vectors in word embedding models are typically scaled to unit length.

If cos(theta) := A.B / (|A|^2 * |B|^2)

And A and B are normalised, then the denominator is 1, and the RHS is equal to the dot product.

Post reply on HN