-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
duckduckgo search and websearch retriever
- Loading branch information
Evgenii Khoroshev
committed
Dec 5, 2023
1 parent
e14cdb0
commit 47abbca
Showing
6 changed files
with
586 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using LangChain.Callback; | ||
using LangChain.Docstore; | ||
using LangChain.Utilities; | ||
|
||
namespace LangChain.Retrievers; | ||
|
||
public sealed class WebSearchRetriever : BaseRetriever | ||
{ | ||
private readonly IWebSearch _webSearch; | ||
private readonly int _k; | ||
|
||
public WebSearchRetriever(IWebSearch webSearch, int k = 10) | ||
{ | ||
_webSearch = webSearch; | ||
_k = k; | ||
} | ||
|
||
protected override async Task<IEnumerable<Document>> GetRelevantDocumentsCoreAsync( | ||
Check warning on line 18 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs
|
||
string query, | ||
CallbackManagerForRetrieverRun runManager = null) | ||
{ | ||
var searchResult = await _webSearch.ResultsAsync(query, _k); | ||
|
||
return searchResult.Select(v => new Document( | ||
v.Body, | ||
new Dictionary<string, object>() | ||
{ | ||
["title"] = v.Title, | ||
["link"] = v.Link | ||
})); | ||
} | ||
} |
Oops, something went wrong.