Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch]: Add namespace to allow indexing multiple tables within the same schema #6341

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading