# There is no way to use custom filters like \`@\>\` with \`PGVectorStore\`

**URL:** <https://forum.langchain.com/t/there-is-no-way-to-use-custom-filters-like-with-pgvectorstore/4594>\
**Category:** LangChain\
**Tags:** js-help, feature-request\
**Created:** [September 23, 2026, 3:13am UTC](https://forum.langchain.com/t/there-is-no-way-to-use-custom-filters-like-with-pgvectorstore/4594 "2026-09-23T03:13:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wbyoung](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/wbyoung/32/3578_2.png) [@wbyoung](https://forum.langchain.com/u/wbyoung)\
**Post date:** [September 23, 2026, 3:13am UTC](https://forum.langchain.com/t/there-is-no-way-to-use-custom-filters-like-with-pgvectorstore/4594/1 "2026-09-23T03:13:55Z")

</div>

It appears that it would be easy to subclass `PGVectorStore` and add support for custom operations via the `filters` if the [`buildFilterClauses` method](https://github.com/langchain-ai/langchainjs/blob/12626c25a9acdd72d2c8a68788479440916d38a1/libs/providers/langchain-pgvector/src/vectorstores.ts#L721) were not `private`.

I’m new to the community. Is this the right place to discuss that or should I just open a PR with the change?

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [September 23, 2026, 5:50am UTC](https://forum.langchain.com/t/there-is-no-way-to-use-custom-filters-like-with-pgvectorstore/4594/2 "2026-09-23T05:50:42Z")

</div>

Hello @wbyoung welcome to langchain community, better if you open an issue on [GitHub - langchain-ai/langchainjs: The agent engineering platform · GitHub](https://github.com/langchain-ai/langchainjs), and wait for maintainers response.

---

<div class="post-metadata">

**Author:** ![patrick.donahue](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@patrick.donahue](https://forum.langchain.com/u/patrick.donahue)\
**Post date:** [October 27, 2026, 4:31pm UTC](https://forum.langchain.com/t/there-is-no-way-to-use-custom-filters-like-with-pgvectorstore/4594/3 "2026-10-27T16:31:45Z")

</div>

Opening the PR is still worth it, but you don’t have to wait for it. `private` on `buildFilterClauses` only exists in the `.d.ts`. At runtime it is an ordinary prototype method, and `searchPostgres` calls it through `this`, so a subclass can wrap it. I tried this against a local pgvector with `@langchain/community` 1.1.29:

```ts
import { PGVectorStore, type PGVectorStoreArgs } from "@langchain/community/vectorstores/pgvector";
import type { EmbeddingsInterface } from "@langchain/core/embeddings";

type Clauses = { whereClauses: string[]; parameters: unknown[]; paramCount: number };
const baseBuild = (PGVectorStore.prototype as any).buildFilterClauses;

export class JsonbPGVectorStore extends PGVectorStore {
  declare FilterType: Record<string, any>;

  // initialize() does `new PGVectorStore(...)`, not `new this(...)`,
  // so calling JsonbPGVectorStore.initialize() gives you a plain PGVectorStore.
  static async create(embeddings: EmbeddingsInterface, config: PGVectorStoreArgs & { dimensions?: number }) {
    const { dimensions, ...rest } = config;
    const store = new JsonbPGVectorStore(embeddings, rest);
    await store._initializeClient();
    await store.ensureTableInDatabase(dimensions);
    if (store.collectionTableName) await store.ensureCollectionTableInDatabase();
    return store;
  }
}

(JsonbPGVectorStore.prototype as any).buildFilterClauses = function (
  this: PGVectorStore, filter: Record<string, any>, paramOffset = 0
): Clauses {
  const rest: Record<string, unknown> = {};
  const contains: [string, unknown][] = [];
  for (const [k, v] of Object.entries(filter)) {
    if (v && typeof v === "object" && "contains" in v) contains.push([k, v.contains]);
    else rest[k] = v;
  }
  const out: Clauses = baseBuild.call(this, rest, paramOffset);
  for (const [k, v] of contains) {
    out.paramCount += 1;
    out.whereClauses.push(`${this.metadataColumnName}->'${k}' @> $${out.paramCount}::jsonb`);
    out.parameters.push(JSON.stringify(v));
  }
  return out;
};

```

Then `similaritySearch("q", 10, { kind: "x", tags: { contains: ["red", "blue"] } })` mixes the built-in operators with `@>`. With three docs tagged `[red, blue]`, `[red]` and `[green]`, `{ tags: { contains: ["red", "blue"] } }` returned only the first one. The built-in `arrayContains` returned the first two, because it compiles to `?|` (matches any element), not containment. It type-checks under `--strict`.

Two things to watch. The key goes into the SQL as a string, same as the built-in operators, so only use trusted keys. And the `initialize()` issue above is easy to miss, because the filter is silently ignored. That could be a second small fix for the PR.
