Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Dec 24, 2024
1 parent 58931bf commit 20cd43c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ npm install pdf-parse fast-xml-parser

```typescript
const retriever = new ArxivRetriever({
returnFullDocuments: false, // Set to true to fetch full documents (PDFs)
getFullDocuments: false, // Set to true to fetch full documents (PDFs)
maxSearchResults: 5, // Maximum number of results to retrieve
});
```
Expand Down
4 changes: 2 additions & 2 deletions examples/src/retrievers/arxiv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const run = async () => {

const queryId = "1605.08386 2103.03404";
const retrieverById = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: 5,
});
const documentsById = await retrieverById.invoke(queryId);
Expand Down Expand Up @@ -42,7 +42,7 @@ export const run = async () => {

const queryNat = "What is the ImageBind model?";
const retrieverByNat = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 2,
});
const documentsByQuery = await retrieverByNat.invoke(queryNat);
Expand Down
9 changes: 4 additions & 5 deletions libs/langchain-community/src/retrievers/arxiv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "../utils/arxiv.js";

export type ArxivRetrieverOptions = {
returnFullDocuments?: boolean;
getFullDocuments?: boolean;
maxSearchResults?: number;
} & BaseRetrieverInput;

Expand All @@ -22,22 +22,21 @@ export class ArxivRetriever extends BaseRetriever {

lc_namespace = ["langchain", "retrievers", "arxiv_retriever"];

returnFullDocuments = false;
getFullDocuments = false;

maxSearchResults = 10;

constructor(options: ArxivRetrieverOptions = {}) {
super(options);
this.returnFullDocuments =
options.returnFullDocuments ?? this.returnFullDocuments;
this.getFullDocuments = options.getFullDocuments ?? this.getFullDocuments;
this.maxSearchResults = options.maxSearchResults ?? this.maxSearchResults;
}

async _getRelevantDocuments(query: string): Promise<Document[]> {
try {
const results = await searchArxiv(query, this.maxSearchResults);

if (this.returnFullDocuments) {
if (this.getFullDocuments) {
// Fetch and parse PDFs to get full documents
return await loadDocsFromResults(results);
} else {
Expand Down
32 changes: 16 additions & 16 deletions libs/langchain-community/src/retrievers/tests/arxiv.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ArxivRetriever } from "../arxiv.js";
test("ArxivRetriever fetching document summaries test", async () => {
// Sample integration test for ArxivRetriever using the "machine learning" query
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 5,
});
const query = "machine learning";
Expand Down Expand Up @@ -43,7 +43,7 @@ test("ArxivRetriever fetching document summaries test", async () => {
test("ArxivRetriever fetching document summaries with invalid query test", async () => {
// Sample test for ArxivRetriever using an invalid query
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 5,
});
const query = "fjalsdkjfw";
Expand All @@ -56,7 +56,7 @@ test("ArxivRetriever fetching document summaries with invalid query test", async
test("ArxivRetriever fetching document summaries with empty query test", async () => {
// Sample test for ArxivRetriever using an empty query
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 5,
});
const query = "";
Expand All @@ -70,7 +70,7 @@ test("ArxivRetriever fetching document summaries with invalid maxSearchResults t
// Sample test for ArxivRetriever using an invalid maxSearchResults
try {
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: -1,
});
const query = "machine learning";
Expand All @@ -87,7 +87,7 @@ test("ArxivRetriever fetching document summaries with zero maxSearchResults test
// Sample test for ArxivRetriever using an zero maxSearchResults
try {
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: 0,
});
const query = "machine learning";
Expand All @@ -103,7 +103,7 @@ test("ArxivRetriever fetching document summaries with zero maxSearchResults test
test("ArxivRetriever fetching full documents test", async () => {
// Sample test for fetching full documents with ArxivRetriever
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: 5,
});
const query = "machine learning";
Expand Down Expand Up @@ -145,7 +145,7 @@ test("ArxivRetriever fetching full documents test", async () => {
test("ArxivRetriever fetching full documents with invalid query test", async () => {
// Sample test for fetching full documents with ArxivRetriever using an invalid query
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: 5,
});
const query = "fjalsdkjfw";
Expand All @@ -158,7 +158,7 @@ test("ArxivRetriever fetching full documents with invalid query test", async ()
test("ArxivRetriever fetching full documents with empty query test", async () => {
// Sample test for fetching full documents with ArxivRetriever using an empty query
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: 5,
});
const query = "";
Expand All @@ -172,7 +172,7 @@ test("ArxivRetriever fetching full documents with invalid maxSearchResults test"
// Sample test for fetching full documents with ArxivRetriever using an invalid maxSearchResults
try {
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: -1,
});
const query = "machine learning";
Expand All @@ -189,7 +189,7 @@ test("ArxivRetriever fetching full documents with zero maxSearchResults", async
// Sample test for fetching full documents with ArxivRetriever using an zero maxSearchResults
try {
const retriever = new ArxivRetriever({
returnFullDocuments: true,
getFullDocuments: true,
maxSearchResults: 0,
});
const query = "machine learning";
Expand All @@ -206,7 +206,7 @@ test("ArxivRetriever search articles by id test", async () => {
// Sample test for fetching articles by arXiv IDs
const fetchIds = "2103.03404 2103.03405";
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 5,
});
const results = await retriever.invoke(fetchIds);
Expand Down Expand Up @@ -244,7 +244,7 @@ test("ArxivRetriever search articles by id with invalid id test", async () => {
// Sample test for fetching articles by arXiv IDs with an invalid ID
const fetchIds = "2103.03404 2103.03405 1234.56789";
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 5,
});
const results = await retriever.invoke(fetchIds);
Expand All @@ -257,7 +257,7 @@ test("ArxivRetriever search articles by id with empty id test", async () => {
// Sample test for fetching articles by arXiv IDs with an empty ID
const fetchIds = "";
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 5,
});
const results = await retriever.invoke(fetchIds);
Expand All @@ -271,7 +271,7 @@ test("ArxivRetriever search articles by id with invalid maxSearchResults test",
try {
const fetchIds = "2103.03404 2103.03405";
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: -1,
});
const results = await retriever.invoke(fetchIds);
Expand All @@ -288,7 +288,7 @@ test("ArxivRetriever search articles by id with invalid id and maxSearchResults
try {
const fetchIds = "2103.03404 2103.03405 1234.56789";
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: -1,
});
const results = await retriever.invoke(fetchIds);
Expand All @@ -305,7 +305,7 @@ test("ArxivRetriever search articles by id with invalid id and zero maxSearchRes
try {
const fetchIds = "2103.03404 2103.03405 1234.56789";
const retriever = new ArxivRetriever({
returnFullDocuments: false,
getFullDocuments: false,
maxSearchResults: 0,
});
const results = await retriever.invoke(fetchIds);
Expand Down

0 comments on commit 20cd43c

Please sign in to comment.