Skip to content

Commit cae3674

Browse files
hntrlSriram-52
andauthored
fix(google-cloud-sql-pg): properly handle explicit metadata columns in PostgresVectorStore (#8909)
Co-authored-by: Sriram Nyshadham <[email protected]>
1 parent 940e087 commit cae3674

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.changeset/tame-impalas-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@langchain/google-cloud-sql-pg": patch
3+
---
4+
5+
properly handle explicit metadata columns in PostgresVectorStore (#8334)

libs/langchain-google-cloud-sql-pg/src/tests/vectorstore.int.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ describe("VectorStore creation", () => {
108108
);
109109
});
110110

111+
// https://github.com/langchain-ai/langchainjs/issues/8334
112+
test("should set metadataColumns if ignoreMetadataColumns is not defined", async () => {
113+
const pvectorArgs: PostgresVectorStoreArgs = {
114+
metadataColumns: ["page", "source"],
115+
};
116+
117+
vectorStoreInstance = await PostgresVectorStore.initialize(
118+
PEInstance,
119+
embeddingService,
120+
CUSTOM_TABLE,
121+
pvectorArgs
122+
);
123+
124+
expect(vectorStoreInstance.metadataColumns).toEqual(["page", "source"]);
125+
});
126+
111127
test("should throw an error if idColumn does not exist", async () => {
112128
const pvectorArgs: PostgresVectorStoreArgs = {
113129
idColumn: "my_id_column",

libs/langchain-google-cloud-sql-pg/src/vectorstore.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ export class PostgresVectorStore extends VectorStore {
365365
delete allColumns[contentColumn];
366366
delete allColumns[embeddingColumn];
367367
allMetadataColumns = Object.keys(allColumns);
368+
} else {
369+
for (const column of metadataColumns) {
370+
if (Object.prototype.hasOwnProperty.call(allColumns, column)) {
371+
allMetadataColumns.push(column);
372+
}
373+
}
368374
}
369375
return new PostgresVectorStore(embeddings, {
370376
engine,

0 commit comments

Comments
 (0)