`PGVectorStore` cannot support custom filters like `@>`
Author: wbyoungCreated Sep 23, 2026Updated Oct 1, 2026
Labelsbug
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
Example of how this could work if the base class had a protected buildFilterClauses:
import { PGVectorStore } from "@langchain/pgvector";
export class SecurePGVectorStore extends PGVectorStore {
/**
* Overriding buildFilterClauses with flat execution and zero-based tracking.
*/
buildFilterClauses(
filter: Record<string, any>,
paramOffset = 0
): { whereClauses: string[]; parameters: any[]; paramCount: number } {
const whereClauses: string[] = [];
let parameters: any[] = [];
let paramCount = paramOffset;
for (const [key, value] of Object.entries(filter)) {
// Intercept the custom JSONB containment operator
if (value && typeof value === "object" && "jsonbContains" in value) {
const targetValue = value.jsonbContains;
// Safely stringify the containment payload and track parameter
parameters.push(JSON.stringify(targetValue));
// Format containment check using zero-based offset counter
whereClauses.push(`metadata::jsonb @> $${paramCount}::jsonb`);
paramCount++;
} else {
// Fall back to standard LangChain operators via super class logic
const result = super.buildFilterClauses({ [key]: value }, paramCount);
// Always concatenate parameters returned by the base method
if (result.parameters && result.parameters.length > 0) {
parameters = parameters.concat(result.parameters);
}
// Append clauses only if they exist
if (result.whereClauses && result.whereClauses.length > 0) {
whereClauses.push(...result.whereClauses);
}
paramCount = result.paramCount;
}
}
return { whereClauses, parameters, paramCount };
}
}Error Message and Stack Trace (if applicable)
No response
Description
It appears that it would be easy to subclass PGVectorStore and add support for custom operations via the filters if the buildFilterClauses method were not private.
I asked this already on the discussion forum and was directed to post here.
System Info
/usr/src/app # cat package.json | grep langchain
"@langchain/core": "^1.2.11",
"@langchain/google": "^0.2.6",
"@langchain/google-vertexai": "^2.3.2",
"@langchain/pgvector": "^0.1.0",
"@langchain/textsplitters": "^1.0.1",
/usr/src/app # cat package.json | grep langchain
"@langchain/core": "^1.2.11",
"@langchain/google": "^0.2.6",
"@langchain/google-vertexai": "^2.3.2",
"@langchain/pgvector": "^0.1.0",
"@langchain/textsplitters": "^1.0.1",
/usr/src/app # cat /etc/alpine-release
3.23.3
/usr/src/app # node --version
v24.13.0
/usr/src/app # pnpm --version
10.30.0
/usr/src/app # Source: langchain-ai/langchainjs