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

Conversation

clemenspeters
Copy link
Contributor

@clemenspeters clemenspeters commented Aug 2, 2024

Issue:

We're working on a tenant based SaaS platform where we use separate tables for each tenant (to avoid infinitely growing tables).

The createHnswIndex function translates into a query like

CREATE INDEX IF NOT EXISTS vector_embedding_hnsw_idx
        ON tenant_123_index USING hnsw ((vector::vector(1536)) vector_cosine_ops)
        WITH (
            m=16,
            ef_construction=64
        );

where the index name is always vector_embedding_hnsw_idx.
Within the same schema in PostgreSQL, the index name must be unique across all tables.

This means it’s created for the first tenant, but not for anyone else since then the index with that static name already exists.

This PR allows to pass an optional namespace string to createHnswIndex which is used a prefixing the index name.

@PetersClemens

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 2, 2024
Copy link

vercel bot commented Aug 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2024 9:29pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview Aug 2, 2024 9:29pm

Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for pushing this update

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Aug 2, 2024
Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format CI action is failing, could you run yarn format from inside libs/langchain-community and push up the changes? Thanks

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Aug 2, 2024
@jacoblee93 jacoblee93 changed the title Add namespace to allow indexing multiple tables within the same schema community[patch]: Add namespace to allow indexing multiple tables within the same schema Aug 3, 2024
@jacoblee93 jacoblee93 merged commit 4fb4613 into langchain-ai:main Aug 3, 2024
34 checks passed
@clemenspeters clemenspeters deleted the add-namespace-to-pg-index-name branch August 3, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases lgtm PRs that are ready to be merged as-is size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants