-
-
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.
feat: duckduckgo search and websearch retriever (#87)
Co-authored-by: Evgenii Khoroshev <[email protected]>
- Loading branch information
1 parent
9105ea8
commit 79a6e56
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) | ||
Check warning on line 12 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs GitHub Actions / Build, test and publish / Build, test and publish
|
||
{ | ||
_webSearch = webSearch; | ||
_k = k; | ||
} | ||
|
||
protected override async Task<IEnumerable<Document>> GetRelevantDocumentsCoreAsync( | ||
Check warning on line 18 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs GitHub Actions / Build, test and publish / Build, test and publish
Check warning on line 18 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs GitHub Actions / Build, test and publish / Build, test and publish
|
||
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.