Skip to content

Commit

Permalink
feat: add filters to ChaindeskRetriever (#3314)
Browse files Browse the repository at this point in the history
* feat: add filters to `ChaindeskRetriver`

reference: https://docs.chaindesk.ai/api-reference/endpoint/datastores/query

* rename filter to filters

* run yarn format
  • Loading branch information
antoinewg authored Nov 20, 2023
1 parent d24872c commit 2dd5606
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion langchain/src/retrievers/chaindesk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ChaindeskRetrieverArgs
BaseRetrieverInput {
datastoreId: string;
topK?: number;
filter?: Record<string, unknown>;
apiKey?: string;
}

Expand Down Expand Up @@ -41,15 +42,24 @@ export class ChaindeskRetriever extends BaseRetriever {

topK?: number;

filter?: Record<string, unknown>;

apiKey?: string;

constructor({ datastoreId, apiKey, topK, ...rest }: ChaindeskRetrieverArgs) {
constructor({
datastoreId,
apiKey,
topK,
filter,
...rest
}: ChaindeskRetrieverArgs) {
super();

this.caller = new AsyncCaller(rest);
this.datastoreId = datastoreId;
this.apiKey = apiKey;
this.topK = topK;
this.filter = filter;
}

async getRelevantDocuments(query: string): Promise<Document[]> {
Expand All @@ -61,6 +71,7 @@ export class ChaindeskRetriever extends BaseRetriever {
body: JSON.stringify({
query,
...(this.topK ? { topK: this.topK } : {}),
...(this.filter ? { filters: this.filter } : {}),
}),
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 2dd5606

Please sign in to comment.