mirror of
https://github.com/lancedb/lancedb.git
synced 2026-06-03 20:30:42 +00:00
feat: allow Python and Typescript users to create Sessions (#2530)
## Summary - Exposes `Session` in Python and Typescript so users can set the `index_cache_size_bytes` and `metadata_cache_size_bytes` * The `Session` is attached to the `Connection`, and thus shared across all tables in that connection. - Adds deprecation warnings for table-level cache configuration 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
38
python/python/tests/test_session.py
Normal file
38
python/python/tests/test_session.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
import lancedb
|
||||
|
||||
|
||||
def test_session_cache_configuration(tmp_path):
|
||||
"""Test Session cache configuration and basic functionality."""
|
||||
# Create session with small cache limits for testing
|
||||
index_cache_size = 1024 * 1024 # 1MB
|
||||
metadata_cache_size = 512 * 1024 # 512KB
|
||||
|
||||
session = lancedb.Session(
|
||||
index_cache_size_bytes=index_cache_size,
|
||||
metadata_cache_size_bytes=metadata_cache_size,
|
||||
)
|
||||
|
||||
# Record initial cache state
|
||||
initial_cache_size = session.size_bytes
|
||||
initial_cache_items = session.approx_num_items
|
||||
|
||||
# Test session works with database connection
|
||||
db = lancedb.connect(tmp_path, session=session)
|
||||
|
||||
# Create and use a table to exercise the session
|
||||
data = [{"id": i, "text": f"item {i}"} for i in range(100)]
|
||||
table = db.create_table("test", data)
|
||||
results = list(table.to_arrow().to_pylist())
|
||||
|
||||
assert len(results) == 100
|
||||
|
||||
# Verify cache usage increased after operations
|
||||
final_cache_size = session.size_bytes
|
||||
final_cache_items = session.approx_num_items
|
||||
|
||||
assert final_cache_size > initial_cache_size # Cache should have grown
|
||||
assert final_cache_items >= initial_cache_items # Items should not decrease
|
||||
assert initial_cache_size < index_cache_size + metadata_cache_size
|
||||
Reference in New Issue
Block a user