Skip to content

fix(lancedb): use paginated __contains__ for table existence check - #86

Open
zzx04-cool wants to merge 1 commit into
aiming-lab:mainfrom
zzx04-cool:fix/lancedb-table-existence-pagination
Open

zzx04-cool wants to merge 1 commit into
aiming-lab:mainfrom
zzx04-cool:fix/lancedb-table-existence-pagination

Conversation

@zzx04-cool

Copy link
Copy Markdown

Problem

When a LanceDB database contains more than 10 tables, reopening an existing memory table fails with Table '<name>' already exists.

LanceDBVectorStoreBackend._init_table() checks existence via self.table_name not in self.db.table_names(). In recent LanceDB versions, table_names() is deprecated and defaults to returning only the first 10 tables. An existing table beyond that first page is incorrectly treated as nonexistent, so the backend calls create_table(), which fails because the table actually already exists.

Solution

Replace self.db.table_names() with self.db (LanceDB Connection.__contains__), which iterates through all table-list pages instead of checking only the first 10.

# before
if self.table_name not in self.db.table_names():

# after
if self.table_name not in self.db:

Changes

  • simplemem/core/database/vector_store_backend.py: one-line fix in _init_table() — use self.db membership test instead of self.db.table_names().
  • tests/test_lancedb_table_pagination.py: new regression test file with 3 cases:
    1. Existing table beyond the first 10-result page is opened (not created).
    2. A genuinely new table is created.
    3. An existing table within the first page is opened correctly.

Testing

  • Environment: Python 3.14, Windows 11 (logic is OS-independent).
  • Test command: python -m pytest tests/test_lancedb_table_pagination.py -v
  • The tests mock lancedb.connect with a _MockDB whose table_names() returns only the first 10 entries (reproducing the deprecated default limit) while __contains__ sees all 15 tables. This directly exercises the bug path.
  • Existing tests in tests/test_vector_store_backend.py are unaffected: the change only replaces the membership-check expression, and the happy path (table within first page / new table) behaves identically.

Notes

LanceDB's table_names() defaults to a 10-table limit, so existing
tables beyond the first page were incorrectly treated as nonexistent,
causing create_table() to fail with "Table already exists".

Replace the membership check with `self.table_name not in self.db`,
which uses LanceDB's Connection.__contains__ that iterates all pages.

Adds regression tests covering tables beyond the first page, new
tables, and tables within the first page.

Closes aiming-lab#85
@zzx04-cool

Copy link
Copy Markdown
Author

Gentle ping: this PR has been ready for review for 5 days. It's a one-line fix (plus regression tests) for the LanceDB table_names() pagination issue described in #85. Happy to address any feedback — just let me know.

@zzx04-cool

Copy link
Copy Markdown
Author

Gentle follow-up on this PR. It's been open for a while and remains ready for review. Please let me know if you'd like any adjustments — happy to iterate.

1 similar comment
@zzx04-cool

Copy link
Copy Markdown
Author

Gentle follow-up on this PR. It's been open for a while and remains ready for review. Please let me know if you'd like any adjustments — happy to iterate.

@zzx04-cool

Copy link
Copy Markdown
Author

Following up once more: this PR has been open for three weeks and is still mergeable as-is — a one-line fix plus regression tests for #85. If there are no objections, could a maintainer review and merge it? If anything needs adjustment, please leave a note and I'll address it promptly. If the change isn't a fit for the project, a quick comment would also be appreciated so I can close it and keep the queue tidy. Thanks!

@zzx04-cool

Copy link
Copy Markdown
Author

Friendly ping — this has been open for about three weeks and is still mergeable. Is there anything you'd like changed before a review?

The change replaces the unpaginated LanceDB table_names() check with the paginated __contains__ path so table existence lookups don't materialize every table name, and adds a test covering a store with more tables than one page. Files: simplemem/core/database/vector_store_backend.py, tests/test_lancedb_table_pagination.py.

Happy to drop the test or reshape the helper if you'd prefer the lookup inlined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LanceDB table existence check fails when more than 10 memory tables exist

1 participant