-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(): add elasticsearch hybrid search #9385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
| return documentIds; | ||
| } | ||
|
|
||
| async similaritySearch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default value inferred from the VectorStore class that we extend from
langchainjs/libs/langchain-core/src/vectorstores.ts
Lines 661 to 671 in 87f120b
| async similaritySearch( | |
| query: string, | |
| k = 4, | |
| filter: this["FilterType"] | undefined = undefined, | |
| _callbacks: Callbacks | undefined = undefined // implement passing to embedQuery later | |
| ): Promise<DocumentInterface[]> { | |
| const results = await this.similaritySearchVectorWithScore( | |
| await this.embeddings.embedQuery(query), | |
| k, | |
| filter | |
| ); |
2d59bda to
73246de
Compare
Elasticsearch Hybrid Search Implementation
Summary
This PR adds hybrid search support to the Elasticsearch vector store integration in LangChain.js. Hybrid search combines semantic (vector) search with lexical (BM25 full-text) search using Reciprocal Rank Fusion (RRF) for improved search relevance.
Related documentation PR: langchain-ai/docs#1466
Features
1. Hybrid Search Strategy
HybridRetrievalStrategyclass for configuring hybrid search2. Backward Compatible
Implementation Details
New Classes
HybridRetrievalStrategyConfigConfiguration interface for hybrid search:
HybridRetrievalStrategyStrategy class implementing hybrid search:
Modified Methods
similaritySearch()similaritySearchVectorWithScore()hybridSearchVectorWithScore()when strategy is presentNew:
hybridSearchVectorWithScore()retrieverAPI with RRFUsage
Basic Vector Search (No Change)
Hybrid Search (New)
Core Implementation
libs/langchain-community/src/vectorstores/elasticsearch.ts(+145 lines)HybridRetrievalStrategyConfiginterfaceHybridRetrievalStrategyclassElasticClientArgsinterfacehybridSearchVectorWithScore()methodsimilaritySearch()andsimilaritySearchVectorWithScore()