Skip to content
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

all[patch]: Replace .getRelevantDocuments with .invoke #5748

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/core_docs/docs/tutorials/agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ const vectorstore = await MemoryVectorStore.fromDocuments(
);
const retriever = vectorstore.asRetriever();

const retrieverResult = await retriever.getRelevantDocuments(
"how to upload a dataset"
);
const retrieverResult = await retriever.invoke("how to upload a dataset");
console.log(retrieverResult[0]);

/*
Expand Down
4 changes: 2 additions & 2 deletions docs/core_docs/docs/tutorials/rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
" outputParser: new StringOutputParser(),\n",
"})\n",
"\n",
"const retrievedDocs = await retriever.getRelevantDocuments(\"what is task decomposition\")"
"const retrievedDocs = await retriever.invoke(\"what is task decomposition\")"
]
},
{
Expand Down Expand Up @@ -817,7 +817,7 @@
" prompt: customRagPrompt,\n",
" outputParser: new StringOutputParser(),\n",
"})\n",
"const context = await retriever.getRelevantDocuments(\"what is task decomposition\");\n",
"const context = await retriever.invoke(\"what is task decomposition\");\n",
"\n",
"await ragChain.invoke({\n",
" question: \"What is Task Decomposition?\",\n",
Expand Down
4 changes: 1 addition & 3 deletions examples/src/retrievers/parent_document_retriever_rerank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ await retriever.addDocuments(docs);

// This will search for documents in vector store and return for LLM already reranked and sorted document
// with appropriate minimum relevance score
const retrievedDocs = await retriever.getRelevantDocuments(
"What is Pam's favorite color?"
);
const retrievedDocs = await retriever.invoke("What is Pam's favorite color?");

// Pam's favorite color is returned first!
console.log(JSON.stringify(retrievedDocs, null, 2));
Expand Down
8 changes: 4 additions & 4 deletions examples/src/retrievers/qdrant_self_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ const selfQueryRetriever = SelfQueryRetriever.fromLLM({
* We can also ask questions like "Which movies are either comedy or drama and are less than 90 minutes?".
* The retriever will automatically convert these questions into queries that can be used to retrieve documents.
*/
const query1 = await selfQueryRetriever.getRelevantDocuments(
const query1 = await selfQueryRetriever.invoke(
"Which movies are less than 90 minutes?"
);
const query2 = await selfQueryRetriever.getRelevantDocuments(
const query2 = await selfQueryRetriever.invoke(
"Which movies are rated higher than 8.5?"
);
const query3 = await selfQueryRetriever.getRelevantDocuments(
const query3 = await selfQueryRetriever.invoke(
"Which cool movies are directed by Greta Gerwig?"
);
const query4 = await selfQueryRetriever.getRelevantDocuments(
const query4 = await selfQueryRetriever.invoke(
"Which movies are either comedy or drama and are less than 90 minutes?"
);
console.log(query1, query2, query3, query4);
2 changes: 1 addition & 1 deletion langchain-core/src/retrievers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export abstract class BaseRetriever<
input: string,
options?: RunnableConfig
): Promise<DocumentInterface<Metadata>[]> {
return this.getRelevantDocuments(input, ensureConfig(options));
return this.invoke(input, ensureConfig(options));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion langchain-core/src/structured_query/functional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type FunctionFilter = (document: Document) => boolean;
* @example
* ```typescript
* const functionalTranslator = new FunctionalTranslator();
* const relevantDocuments = await functionalTranslator.getRelevantDocuments(
* const relevantDocuments = await functionalTranslator.invoke(
* "Which movies are rated higher than 8.5?",
* );
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createRetrieverTool(
{ input }: { input: string },
runManager?: CallbackManagerForToolRun
) => {
const docs = await retriever.getRelevantDocuments(
const docs = await retriever.invoke(
input,
runManager?.getChild("retriever")
);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/chains/conversational_retrieval_chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class ConversationalRetrievalQAChain
);
}
}
const docs = await this.retriever.getRelevantDocuments(
const docs = await this.retriever.invoke(
newQuestion,
runManager?.getChild("retriever")
);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/chains/retrieval_qa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class RetrievalQAChain
throw new Error(`Question key "${this.inputKey}" not found.`);
}
const question: string = values[this.inputKey];
const docs = await this.retriever.getRelevantDocuments(
const docs = await this.retriever.invoke(
question,
runManager?.getChild("retriever")
);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/experimental/autogpt/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class AutoGPTPrompt
const usedTokens =
(await this.tokenCounter(basePrompt.content)) +
(await this.tokenCounter(timePrompt.content));
const relevantDocs = await memory.getRelevantDocuments(
const relevantDocs = await memory.invoke(
JSON.stringify(previousMessages.slice(-10))
);
const relevantMemory = relevantDocs.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ export class ViolationOfExpectationsChain
// Only extract the first relevant doc from the retriever. We don't need more than one.
const relevantInsightsDocuments = await Promise.all(
insights.map(async (insight) => {
const relevantInsight = await this.retriever.getRelevantDocuments(
insight
);
const relevantInsight = await this.retriever.invoke(insight);
return relevantInsight[0];
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class GenerativeAgentMemoryChain extends BaseChain {
_now?: Date,
runManager?: CallbackManagerForChainRun
): Promise<Document[]> {
return this.memoryRetriever.getRelevantDocuments(
return this.memoryRetriever.invoke(
observation,
runManager?.getChild("memory_retriever")
);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/memory/vector_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class VectorStoreRetrieverMemory
*/
async loadMemoryVariables(values: InputValues): Promise<MemoryVariables> {
const query = getInputValue(values, this.inputKey);
const results = await this.vectorStoreRetriever.getRelevantDocuments(query);
const results = await this.vectorStoreRetriever.invoke(query);
return {
[this.memoryKey]: this.returnDocs
? results
Expand Down
4 changes: 2 additions & 2 deletions langchain/src/retrievers/contextual_compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ContextualCompressionRetrieverArgs extends BaseRetrieverInput {
* baseCompressor: new LLMChainExtractor(),
* baseRetriever: new HNSWLib().asRetriever(),
* });
* const retrievedDocs = await retriever.getRelevantDocuments(
* const retrievedDocs = await retriever.invoke(
* "What did the speaker say about Justice Breyer?",
* );
* ```
Expand All @@ -54,7 +54,7 @@ export class ContextualCompressionRetriever extends BaseRetriever {
query: string,
runManager?: CallbackManagerForRetrieverRun
): Promise<DocumentInterface[]> {
const docs = await this.baseRetriever.getRelevantDocuments(
const docs = await this.baseRetriever.invoke(
query,
runManager?.getChild("base_retriever")
);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/document_compressors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export abstract class BaseDocumentCompressor {
* includeRawContent: true,
* }),
* });
* const retrievedDocs = await retriever.getRelevantDocuments(
* const retrievedDocs = await retriever.invoke(
* "What did the speaker say about Justice Breyer in the 2022 State of the Union?",
* );
* console.log({ retrievedDocs });
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/hyde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type HydeRetrieverOptions<V extends VectorStore> =
* "My favourite food is pasta.",
* ].map((pageContent) => new Document({ pageContent })),
* );
* const results = await retriever.getRelevantDocuments(
* const results = await retriever.invoke(
* "What is my favourite food?",
* );
* ```
Expand Down
7 changes: 2 additions & 5 deletions langchain/src/retrievers/multi_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface MultiQueryRetrieverInput extends BaseRetrieverInput {
* retriever: new MemoryVectorStore().asRetriever(),
* verbose: true,
* });
* const retrievedDocs = await retriever.getRelevantDocuments(
* const retrievedDocs = await retriever.invoke(
* "What are mitochondria made of?",
* );
* ```
Expand Down Expand Up @@ -159,10 +159,7 @@ export class MultiQueryRetriever extends BaseRetriever {
const documents: Document[] = [];
await Promise.all(
queries.map(async (query) => {
const docs = await this.retriever.getRelevantDocuments(
query,
runManager?.getChild()
);
const docs = await this.retriever.invoke(query, runManager?.getChild());
documents.push(...docs);
})
);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/multi_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface MultiVectorRetrieverInput extends BaseRetrieverInput {
* parentK: 5,
* });
*
* const retrieverResult = await retriever.getRelevantDocuments("justice breyer");
* const retrieverResult = await retriever.invoke("justice breyer");
* console.log(retrieverResult[0].pageContent.length);
* ```
*/
Expand Down
4 changes: 2 additions & 2 deletions langchain/src/retrievers/parent_document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type ParentDocumentRetrieverFields = MultiVectorRetrieverInput & {
*
* const parentDocuments = await getDocuments();
* await retriever.addDocuments(parentDocuments);
* const retrievedDocs = await retriever.getRelevantDocuments("justice breyer");
* const retrievedDocs = await retriever.invoke("justice breyer");
* ```
*/
export class ParentDocumentRetriever extends MultiVectorRetriever {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class ParentDocumentRetriever extends MultiVectorRetriever {
async _getRelevantDocuments(query: string): Promise<Document[]> {
let subDocs: SubDocs = [];
if (this.childDocumentRetriever) {
subDocs = await this.childDocumentRetriever.getRelevantDocuments(query);
subDocs = await this.childDocumentRetriever.invoke(query);
} else {
subDocs = await this.vectorstore.similaritySearch(query, this.childK);
}
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/self_query/chroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation
* structuredQueryTranslator: chromaTranslator,
* });
*
* const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
* const relevantDocuments = await selfQueryRetriever.invoke(
* "Which movies are directed by Greta Gerwig?",
* );
* ```
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/self_query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface SelfQueryRetrieverArgs<T extends VectorStore>
* attributeInfo: attributeInfo,
* structuredQueryTranslator: new FunctionalTranslator(),
* });
* const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
* const relevantDocuments = await selfQueryRetriever.invoke(
* "Which movies are directed by Greta Gerwig?",
* );
* ```
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/self_query/pinecone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation
* structuredQueryTranslator: new PineconeTranslator(),
* });
*
* const queryResult = await selfQueryRetriever.getRelevantDocuments(
* const queryResult = await selfQueryRetriever.invoke(
* "Which movies are directed by Greta Gerwig?",
* );
* ```
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/self_query/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type SupabaseMetadata = any;
* structuredQueryTranslator: new SupabaseTranslator(),
* });
*
* const queryResult = await selfQueryRetriever.getRelevantDocuments(
* const queryResult = await selfQueryRetriever.invoke(
* "Which movies are directed by Greta Gerwig?",
* );
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ test("Memory Vector Store Self Query Retriever Test", async () => {
structuredQueryTranslator: new FunctionalTranslator(),
});

const query1 = await selfQueryRetriever.getRelevantDocuments(
const query1 = await selfQueryRetriever.invoke(
"Which movies are less than 90 minutes?"
);
console.log(query1);
expect(query1.length).toEqual(0);

const query2 = await selfQueryRetriever.getRelevantDocuments(
const query2 = await selfQueryRetriever.invoke(
"Which movies are rated higher than 8.5?"
);
console.log(query2);
expect(query2.length).toEqual(2);

const query3 = await selfQueryRetriever.getRelevantDocuments(
const query3 = await selfQueryRetriever.invoke(
"Which movies are directed by Greta Gerwig?"
);
console.log(query3);
Expand Down Expand Up @@ -221,25 +221,25 @@ test("Memory Vector Store Self Query Retriever Test With Default Filter Or Merge
},
});

const query1 = await selfQueryRetriever.getRelevantDocuments(
const query1 = await selfQueryRetriever.invoke(
"Which movies are less than 90 minutes?"
);
console.log(query1);
expect(query1.length).toEqual(6);

const query2 = await selfQueryRetriever.getRelevantDocuments(
const query2 = await selfQueryRetriever.invoke(
"Which movies are rated higher than 8.5?"
);
console.log(query2);
expect(query2.length).toEqual(7);

const query3 = await selfQueryRetriever.getRelevantDocuments(
const query3 = await selfQueryRetriever.invoke(
"Which movies are directed by Greta Gerwig?"
);
console.log(query3);
expect(query3.length).toEqual(6);

const query4 = await selfQueryRetriever.getRelevantDocuments(
const query4 = await selfQueryRetriever.invoke(
"Awawawa au au au wawawawa hello?"
);
console.log(query4);
Expand Down Expand Up @@ -362,25 +362,25 @@ test("Memory Vector Store Self Query Retriever Test With Default Filter And Merg
},
});

const query1 = await selfQueryRetriever.getRelevantDocuments(
const query1 = await selfQueryRetriever.invoke(
"Which movies are less than 90 minutes?"
);
console.log(query1);
expect(query1.length).toEqual(0);

const query2 = await selfQueryRetriever.getRelevantDocuments(
const query2 = await selfQueryRetriever.invoke(
"Which movies are rated higher than 8.5?"
);
console.log(query2);
expect(query2.length).toEqual(2);

const query3 = await selfQueryRetriever.getRelevantDocuments(
const query3 = await selfQueryRetriever.invoke(
"Which movies are directed by Greta Gerwig?"
);
console.log(query3);
expect(query3.length).toEqual(1);

const query4 = await selfQueryRetriever.getRelevantDocuments(
const query4 = await selfQueryRetriever.invoke(
"Awawawa au au au wawawawa hello?"
);
console.log(query4);
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/self_query/weaviate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type WeaviateStructuredQueryResult = {
* structuredQueryTranslator: new WeaviateTranslator(),
* });
*
* const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
* const relevantDocuments = await selfQueryRetriever.invoke(
* "Which movies are rated higher than 8.5?",
* );
* ```
Expand Down
8 changes: 2 additions & 6 deletions langchain/src/retrievers/tests/hyde.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ test("Hyde retriever", async () => {
].map((pageContent) => new Document({ pageContent }))
);

const results = await retriever.getRelevantDocuments(
"What is my favourite food?"
);
const results = await retriever.invoke("What is my favourite food?");

expect(results.length).toBe(1);
console.log(results);
Expand All @@ -51,9 +49,7 @@ test("Hyde retriever with default prompt template", async () => {
].map((pageContent) => new Document({ pageContent }))
);

const results = await retriever.getRelevantDocuments(
"What is my favourite food?"
);
const results = await retriever.invoke("What is my favourite food?");

expect(results.length).toBe(1);
console.log(results);
Expand Down
Loading
Loading