Skip to content

Commit caf620b

Browse files
authored
Fix self-query retriever tracing (#6515)
1 parent 54608ba commit caf620b

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export {
2-
FunctionFilter,
2+
type FunctionFilter,
33
FunctionalTranslator,
44
} from "@langchain/core/structured_query";

langchain/src/retrievers/self_query/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export class SelfQueryRetriever<T extends VectorStore>
101101
): Promise<Document<Record<string, unknown>>[]> {
102102
const generatedStructuredQuery = await this.queryConstructor.invoke(
103103
{ query },
104-
runManager?.getChild("query_constructor")
104+
{
105+
callbacks: runManager?.getChild("query_constructor"),
106+
runName: "query_constructor",
107+
}
105108
);
106109

107110
const nextArg = this.structuredQueryTranslator.visitStructuredQuery(
@@ -122,12 +125,12 @@ export class SelfQueryRetriever<T extends VectorStore>
122125
myQuery = generatedQuery;
123126
}
124127

125-
return this.vectorStore.similaritySearch(
126-
myQuery,
127-
this.searchParams?.k,
128-
filter,
129-
runManager?.getChild("vectorstore")
130-
);
128+
return this.vectorStore
129+
.asRetriever({
130+
k: this.searchParams?.k,
131+
filter,
132+
})
133+
.invoke(myQuery, { callbacks: runManager?.getChild("retriever") });
131134
}
132135

133136
/**

langchain/src/retrievers/self_query/tests/memory_self_query.int.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from "@jest/globals";
22
import { Document } from "@langchain/core/documents";
3-
import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";
3+
import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";
44
import { AttributeInfo } from "../../../chains/query_constructor/index.js";
55
import { SelfQueryRetriever } from "../index.js";
66
import { FunctionalTranslator } from "../functional.js";
@@ -73,8 +73,8 @@ test("Memory Vector Store Self Query Retriever Test", async () => {
7373
];
7474

7575
const embeddings = new OpenAIEmbeddings();
76-
const llm = new OpenAI({
77-
modelName: "gpt-3.5-turbo",
76+
const llm = new ChatOpenAI({
77+
model: "gpt-4o-mini",
7878
});
7979
const documentContents = "Brief summary of a movie";
8080
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
@@ -203,8 +203,8 @@ test("Memory Vector Store Self Query Retriever Test With Default Filter Or Merge
203203
];
204204

205205
const embeddings = new OpenAIEmbeddings();
206-
const llm = new OpenAI({
207-
modelName: "gpt-3.5-turbo",
206+
const llm = new ChatOpenAI({
207+
model: "gpt-4o-mini",
208208
});
209209
const documentContents = "Brief summary of a movie";
210210
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
@@ -344,8 +344,8 @@ test("Memory Vector Store Self Query Retriever Test With Default Filter And Merg
344344
];
345345

346346
const embeddings = new OpenAIEmbeddings();
347-
const llm = new OpenAI({
348-
modelName: "gpt-3.5-turbo",
347+
const llm = new ChatOpenAI({
348+
model: "gpt-4o-mini",
349349
});
350350
const documentContents = "Brief summary of a movie";
351351
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
@@ -384,5 +384,5 @@ test("Memory Vector Store Self Query Retriever Test With Default Filter And Merg
384384
"Awawawa au au au wawawawa hello?"
385385
);
386386
// console.log(query4);
387-
expect(query4.length).toEqual(0); // this one should return documents since default filter takes over
387+
expect(query4.length).toEqual(7); // this one should return documents since default filter takes over
388388
});

0 commit comments

Comments
 (0)