Skip to content

feat: add v1 of session apis - #27

Merged
yuvalif merged 2 commits into
lancedb:mainfrom
9401adarsh:wip-adashoka-session-bindings
Mar 24, 2026
Merged

yuvalif merged 2 commits into
lancedb:mainfrom
9401adarsh:wip-adashoka-session-bindings

Conversation

@9401adarsh

@9401adarsh 9401adarsh commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR addresses #17.

What's been implemented?

  • Added session FFI types and APIs in Rust under src/connection.rs.
  • Added matching public C API declarations under include/lancedb.h.
  • Added coverage tests for session C API under tests/test_connection.cpp, tests/test_table.cpp and tests/test_query.cpp, tests/test_vector_query.cpp.
  • Added docs under docs/index.rst.

To-Discuss and Pending Items:

  • Object Store Registry - how to go about implementing this interface? Current implementations initiates session with default Object Store Registry, no registry API exposed. (This is deferred for the time being as per our discussion last week).

@9401adarsh

Copy link
Copy Markdown
Contributor Author

Hi @yuvalif, have started work on the issue. Please have a look and let me know your thoughts.

@yuvalif
yuvalif self-requested a review March 9, 2026 15:02
Comment thread tests/test_connection.cpp Resolved
@yuvalif

yuvalif commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

as discussed, please add the following tests:

  • tables: use the same session with multiple tables
  • query: query a table from a db that has a session several times and verify using session stats that there were cache hits

@9401adarsh
9401adarsh force-pushed the wip-adashoka-session-bindings branch from 0ff3616 to dd473f6 Compare March 16, 2026 01:42
Comment thread tests/test_query.cpp Outdated
*/

#include "test_common.h"
#include <iostream>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added print statements to verify cache growth for debugging - might be useful to keep imo. Will remove it if you feel they aren't required.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see my comments below. please use explicit assertions that would print the condition that failed instead of using cout

@9401adarsh
9401adarsh marked this pull request as ready for review March 16, 2026 01:45
@9401adarsh

Copy link
Copy Markdown
Contributor Author

as discussed, please add the following tests:

* tables: use the same session with multiple tables

* query: query a table from a db that has a session several times and verify using session stats that there were cache hits

Hi @yuvalif, have added these tests to the PR as well.

Comment thread tests/test_table.cpp Resolved
Comment thread tests/test_query.cpp Resolved
@9401adarsh
9401adarsh force-pushed the wip-adashoka-session-bindings branch 2 times, most recently from 87b65ff to a718183 Compare March 22, 2026 07:26
@9401adarsh

9401adarsh commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @yuvalif, have added the tests with a deterministic seed as discussed for vector queries.

Currently the tests show the following behavior:

  1. Scalar Query Asserts
/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:330: PASSED:
  REQUIRE( final_index_stats.hits > initial_index_stats.hits )
with expansion:
  22 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:331: PASSED:
  REQUIRE( final_index_stats.misses > initial_index_stats.misses )
with expansion:
  1 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:332: PASSED:
  REQUIRE( final_index_stats.num_entries > initial_index_stats.num_entries )
with expansion:
  2 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:333: PASSED:
  REQUIRE( final_index_stats.size_bytes > initial_index_stats.size_bytes )
with expansion:
  605 (0x25d) > 0

===============================================================================
All tests passed (1148 assertions in 1 test case)
  1. Vector Query Asserts
/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:882: PASSED:
  REQUIRE( final_index_stats.hits > initial_index_stats.hits )
with expansion:
  63 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:883: PASSED:
  REQUIRE( final_index_stats.misses > initial_index_stats.misses )
with expansion:
  1 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:884: PASSED:
  REQUIRE( final_index_stats.num_entries > initial_index_stats.num_entries )
with expansion:
  2 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:885: PASSED:
  REQUIRE( final_index_stats.size_bytes > initial_index_stats.size_bytes )
with expansion:
  606 (0x25e) > 0

This is consistent across multiple runs; should I add a check with these numbers as well ?

@yuvalif

yuvalif commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

Hi @yuvalif, have added the tests with a deterministic seed as discussed for vector queries.

Currently the tests show the following behavior:

  1. Scalar Query Asserts
/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:330: PASSED:
  REQUIRE( final_index_stats.hits > initial_index_stats.hits )
with expansion:
  22 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:331: PASSED:
  REQUIRE( final_index_stats.misses > initial_index_stats.misses )
with expansion:
  1 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:332: PASSED:
  REQUIRE( final_index_stats.num_entries > initial_index_stats.num_entries )
with expansion:
  2 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:333: PASSED:
  REQUIRE( final_index_stats.size_bytes > initial_index_stats.size_bytes )
with expansion:
  605 (0x25d) > 0

===============================================================================
All tests passed (1148 assertions in 1 test case)
  1. Vector Query Asserts
/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:882: PASSED:
  REQUIRE( final_index_stats.hits > initial_index_stats.hits )
with expansion:
  63 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:883: PASSED:
  REQUIRE( final_index_stats.misses > initial_index_stats.misses )
with expansion:
  1 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:884: PASSED:
  REQUIRE( final_index_stats.num_entries > initial_index_stats.num_entries )
with expansion:
  2 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:885: PASSED:
  REQUIRE( final_index_stats.size_bytes > initial_index_stats.size_bytes )
with expansion:
  606 (0x25e) > 0

This is consistent across multiple runs; should I add a check with these numbers as well ?

i think that these assertions are good enough. they would probably also hold true if we use a random seed.
only other assertion i would add is to verify that final_index_stats.hits > final_index_stats.misses to verify that the cache works.

btw, how many queries are performed by the test?

Comment thread tests/test_vector_query.cpp Resolved
Comment thread tests/test_query.cpp Resolved
@9401adarsh

Copy link
Copy Markdown
Contributor Author

Hi @yuvalif, have added the tests with a deterministic seed as discussed for vector queries.
Currently the tests show the following behavior:

  1. Scalar Query Asserts
/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:330: PASSED:
  REQUIRE( final_index_stats.hits > initial_index_stats.hits )
with expansion:
  22 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:331: PASSED:
  REQUIRE( final_index_stats.misses > initial_index_stats.misses )
with expansion:
  1 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:332: PASSED:
  REQUIRE( final_index_stats.num_entries > initial_index_stats.num_entries )
with expansion:
  2 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_query.cpp:333: PASSED:
  REQUIRE( final_index_stats.size_bytes > initial_index_stats.size_bytes )
with expansion:
  605 (0x25d) > 0

===============================================================================
All tests passed (1148 assertions in 1 test case)
  1. Vector Query Asserts
/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:882: PASSED:
  REQUIRE( final_index_stats.hits > initial_index_stats.hits )
with expansion:
  63 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:883: PASSED:
  REQUIRE( final_index_stats.misses > initial_index_stats.misses )
with expansion:
  1 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:884: PASSED:
  REQUIRE( final_index_stats.num_entries > initial_index_stats.num_entries )
with expansion:
  2 > 0

/Users/adarsh9401/Desktop/dev-projects/ceph-rgw-lancedb/lancedb-c/tests/test_vector_query.cpp:885: PASSED:
  REQUIRE( final_index_stats.size_bytes > initial_index_stats.size_bytes )
with expansion:
  606 (0x25e) > 0

This is consistent across multiple runs; should I add a check with these numbers as well ?

i think that these assertions are good enough. they would probably also hold true if we use a random seed. only other assertion i would add is to verify that final_index_stats.hits > final_index_stats.misses to verify that the cache works.

btw, how many queries are performed by the test?

20 queries for both.

@9401adarsh
9401adarsh force-pushed the wip-adashoka-session-bindings branch from a718183 to e79d5ef Compare March 23, 2026 14:31
@9401adarsh

Copy link
Copy Markdown
Contributor Author

Have made all changes, including the new hits > misses check for both tests.

Comment thread tests/test_vector_query.cpp Resolved
… tables) and verify session cache populates after repeated queries

Signed-off-by: 9401adarsh <[email protected]>

tests: fix query test cout with asserts; add more deterministic asserts for validating cache stats behavior

Signed-off-by: 9401adarsh <[email protected]>

tests: add cache behavior monontonic increase for vector and scalar queries

Signed-off-by: 9401adarsh <[email protected]>

tests: add hits > misses check for session stats; nit: refactor

Signed-off-by: 9401adarsh <[email protected]>

fix seed init to inside for loop

Signed-off-by: 9401adarsh <[email protected]>
@9401adarsh
9401adarsh force-pushed the wip-adashoka-session-bindings branch from e79d5ef to 2172c1f Compare March 23, 2026 19:22
@yuvalif
yuvalif self-requested a review March 23, 2026 19:39
@yuvalif
yuvalif merged commit e8a2d05 into lancedb:main Mar 24, 2026
6 checks passed
@9401adarsh
9401adarsh deleted the wip-adashoka-session-bindings branch April 9, 2026 20:53
yuvalif added a commit to yuvalif/lancedb-c that referenced this pull request Jun 8, 2026
this is to allow for deep call stacks that happening
when the query planner is needed.
example of deep call (63 frames) stack backtrace in upsert:

C++                  --- frames lancedb#63-lancedb#61
tokio                --- frames lancedb#60-lancedb#50
lancedb merge logic  --- frames lancedb#49-lancedb#45
lance execution      --- frames lancedb#44-lancedb#28
df physical planning --- frames lancedb#27-lancedb#18
lance scanner        --- frames lancedb#17-lancedb#10
SessionState clone   --- frames lancedb#9-#0

backtrace:
https://gist.github.com/yuvalif/7b3c78bd56765a03163f17377c20544b

Signed-off-by: Yuval Lifshitz <[email protected]>
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.

2 participants