Skip to content

Commit

Permalink
Add namespace to allow indexing multiple tables within the same schema (
Browse files Browse the repository at this point in the history
#6341)

* ✨ Add namespace to allow indexing multiple tables within the same schema

* 🚨 Auto style fixes with `yarn format`
  • Loading branch information
clemenspeters authored Aug 3, 2024
1 parent aef250c commit 4fb4613
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libs/langchain-community/src/vectorstores/pgvector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,18 @@ export class PGVectorStore extends VectorStore {
* @param m - The max number of connections per layer (16 by default). Index build time improves with smaller values, while higher values can speed up search queries.
* @param efConstruction - The size of the dynamic candidate list for constructing the graph (64 by default). A higher value can potentially improve the index quality at the cost of index build time.
* @param distanceFunction - The distance function name you want to use, is automatically selected based on the distanceStrategy.
* @param namespace - The namespace is used to create the index with a specific name. This is useful when you want to create multiple indexes on the same database schema (within the same schema in PostgreSQL, the index name must be unique across all tables).
* @returns Promise that resolves with the query response of creating the index.
*/
async createHnswIndex(config: {
dimensions: number;
m?: number;
efConstruction?: number;
distanceFunction?: string;
namespace?: string;
}): Promise<void> {
let idxDistanceFunction = config?.distanceFunction || "vector_cosine_ops";
const prefix = config?.namespace ? `${config.namespace}_` : "";

switch (this.distanceStrategy) {
case "cosine":
Expand All @@ -709,7 +712,7 @@ export class PGVectorStore extends VectorStore {
throw new Error(`Unknown distance strategy: ${this.distanceStrategy}`);
}

const createIndexQuery = `CREATE INDEX IF NOT EXISTS ${
const createIndexQuery = `CREATE INDEX IF NOT EXISTS ${prefix}${
this.vectorColumnName
}_embedding_hnsw_idx
ON ${this.computedTableName} USING hnsw ((${
Expand Down

0 comments on commit 4fb4613

Please sign in to comment.