lancelot 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cda5bd00de23ad9f4840b1cc7f6e96b7eb4ec124ba902d3901ef36b37594de97
4
- data.tar.gz: 23e84c317e5bcd0f52870c673d0b96f9abf4f3ab97f20eb4e5b8a8047dd1cf1f
3
+ metadata.gz: 1861aeee032e7c7e742136fa606816034a5b22812862265e17bdf5c5ef1717cb
4
+ data.tar.gz: a0154bea94678710902d6696deb71f62e4b0fafafbe4adca8433ddb81c17074b
5
5
  SHA512:
6
- metadata.gz: 32cb3e852ed77b8ec2831b08f93252b5ccb176942c217a366079e1cb2a2a97c4be74247b5f8410a2892852456278a5ec8e5b556bd9ca3379d740b292cc32c15b
7
- data.tar.gz: 718a99dbfcd51dce872feedb87265be86417faba152d6f2512a9391f28e5fc5e115deb0154be52dc029c2771611b71c685f1f143a4d2da5157aaafc28997ffa7
6
+ metadata.gz: 550b2dde6c3868f62ddc1247a44045a07a46352dc4d6b3466876a35b5b4cae6d0df0b93faf41d45cdaec99092e074b72cac67a7a3dec53f268df11bacf791812
7
+ data.tar.gz: 32fab876ba1873e7648b4c9174e773cf69b604d158f7b71449172670363080390a7365b581f121d2d459a5516aaecc9c56f8f36925b1307b290f2f182d266f95
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Lancelot
1
+ <img src="/docs/assets/lancelot-wide.png" alt="lancelot" height="80px">
2
2
 
3
3
  Ruby bindings for [Lance](https://github.com/lancedb/lance), a modern columnar data format for ML. Lancelot provides a Ruby-native interface to Lance, enabling efficient storage and search of multimodal data including text, vectors, and more.
4
4
 
@@ -57,6 +57,25 @@ dataset.vector_search(query_embedding, column: "embedding", limit: 5).each { |r|
57
57
 
58
58
  ## Installation
59
59
 
60
+ ### System Requirements
61
+
62
+ Lancelot requires the Protocol Buffers compiler (`protoc`) to build from source:
63
+
64
+ ```bash
65
+ # macOS (via Homebrew)
66
+ brew install protobuf
67
+
68
+ # Ubuntu/Debian
69
+ sudo apt-get install protobuf-compiler
70
+
71
+ # Other systems
72
+ # Download from https://github.com/protocolbuffers/protobuf/releases
73
+ ```
74
+
75
+ **Note**: The `protoc` compiler is only needed when building the gem from source. Pre-built gems distributed through RubyGems.org do not require `protoc` to be installed.
76
+
77
+ ### Install the Gem
78
+
60
79
  Install the gem and add to the application's Gemfile by executing:
61
80
 
62
81
  ```bash
@@ -276,7 +295,7 @@ bundle exec rake compile
276
295
 
277
296
  ## Contributing
278
297
 
279
- Bug reports and pull requests are welcome on GitHub at https://github.com/cpetersen/lancelot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cpetersen/lancelot/blob/main/CODE_OF_CONDUCT.md).
298
+ Bug reports and pull requests are welcome on GitHub at https://github.com/scientist-labs/lancelot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/scientist-labs/lancelot/blob/main/CODE_OF_CONDUCT.md).
280
299
 
281
300
  ## License
282
301
 
@@ -284,4 +303,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
284
303
 
285
304
  ## Code of Conduct
286
305
 
287
- Everyone interacting in the Lancelot project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cpetersen/lancelot/blob/main/CODE_OF_CONDUCT.md).
306
+ Everyone interacting in the Lancelot project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/scientist-labs/lancelot/blob/main/CODE_OF_CONDUCT.md).
Binary file
Binary file
@@ -11,6 +11,26 @@ use futures::stream::TryStreamExt;
11
11
 
12
12
  use crate::schema::build_arrow_schema;
13
13
  use crate::conversion::{build_record_batch, convert_batch_to_ruby};
14
+ use arrow_schema::DataType;
15
+
16
+ /// Convert Arrow DataType to Ruby-friendly string representation
17
+ fn datatype_to_ruby_string(dtype: &DataType) -> &'static str {
18
+ match dtype {
19
+ DataType::Utf8 | DataType::LargeUtf8 => "string",
20
+ DataType::Boolean => "boolean",
21
+ DataType::Int8 | DataType::Int16 | DataType::Int32 => "int32",
22
+ DataType::Int64 => "int64",
23
+ DataType::UInt8 | DataType::UInt16 | DataType::UInt32 => "int32",
24
+ DataType::UInt64 => "int64",
25
+ DataType::Float32 => "float32",
26
+ DataType::Float64 => "float64",
27
+ DataType::Date32 => "date",
28
+ DataType::Date64 => "datetime",
29
+ DataType::Timestamp(_, _) => "datetime",
30
+ DataType::FixedSizeList(_, _) => "vector", // Will be handled specially
31
+ _ => "unknown"
32
+ }
33
+ }
14
34
 
15
35
  #[magnus::wrap(class = "Lancelot::Dataset", free_immediately, size)]
16
36
  pub struct LancelotDataset {
@@ -121,16 +141,40 @@ impl LancelotDataset {
121
141
 
122
142
  pub fn schema(&self) -> Result<RHash, Error> {
123
143
  let dataset = self.dataset.borrow();
124
- let _dataset = dataset.as_ref()
144
+ let dataset = dataset.as_ref()
125
145
  .ok_or_else(|| Error::new(magnus::exception::runtime_error(), "Dataset not opened"))?;
126
146
 
147
+ // Get the actual schema from the Lance dataset
148
+ let schema = self.runtime.borrow_mut().block_on(async {
149
+ dataset.schema()
150
+ });
151
+
152
+ // Convert Lance schema to Arrow schema
153
+ let arrow_schema: arrow_schema::Schema = schema.into();
154
+ let arrow_schema = Arc::new(arrow_schema);
155
+
127
156
  let ruby = Ruby::get().unwrap();
128
157
  let hash = ruby.hash_new();
129
158
 
130
- // TODO: Read actual schema from Lance dataset once we figure out the 0.31 API
131
- // For now, return a hardcoded schema that matches what we support
132
- hash.aset(Symbol::new("text"), "string")?;
133
- hash.aset(Symbol::new("score"), "float32")?;
159
+ // Iterate over Arrow schema fields
160
+ for field in arrow_schema.fields() {
161
+ let field_name = Symbol::new(&field.name());
162
+
163
+ // Handle vector columns specially
164
+ if let DataType::FixedSizeList(inner_field, dimension) = field.data_type() {
165
+ // Check if it's a vector (float list)
166
+ if matches!(inner_field.data_type(), DataType::Float32 | DataType::Float16) {
167
+ let vector_info = ruby.hash_new();
168
+ vector_info.aset(Symbol::new("type"), "vector")?;
169
+ vector_info.aset(Symbol::new("dimension"), *dimension)?;
170
+ hash.aset(field_name, vector_info)?;
171
+ continue;
172
+ }
173
+ }
174
+
175
+ let field_type = datatype_to_ruby_string(field.data_type());
176
+ hash.aset(field_name, field_type)?;
177
+ }
134
178
 
135
179
  Ok(hash)
136
180
  }
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
4
+
3
5
  module Lancelot
4
6
  class Dataset
5
7
  class << self
@@ -15,10 +17,40 @@ module Lancelot
15
17
  dataset
16
18
  end
17
19
 
18
- def open_or_create(path, schema:)
20
+ def open_or_create(path, schema:, mode: nil)
21
+ # Check if path exists
19
22
  if File.exist?(path)
20
- open(path)
23
+ # Check if it's a file instead of directory
24
+ if File.file?(path)
25
+ if mode == "overwrite"
26
+ # Remove the file and create dataset
27
+ FileUtils.rm_f(path)
28
+ create(path, schema: schema)
29
+ else
30
+ raise ArgumentError, "Path #{path} exists as a file, not a directory. " \
31
+ "Use mode: 'overwrite' to replace it, or choose a different path."
32
+ end
33
+ # Path exists as directory - check if it's a valid Lance dataset
34
+ elsif File.exist?(File.join(path, "_versions"))
35
+ # Valid dataset exists - open it
36
+ open(path)
37
+ elsif !Dir.empty?(path)
38
+ # Non-empty directory that's not a Lance dataset
39
+ if mode == "overwrite"
40
+ # User explicitly wants to overwrite - remove and create new
41
+ FileUtils.rm_rf(path)
42
+ create(path, schema: schema)
43
+ else
44
+ # Fail safely - don't overwrite existing non-dataset directory
45
+ raise ArgumentError, "Directory exists at #{path} but is not a valid Lance dataset. " \
46
+ "Use mode: 'overwrite' to replace it, or choose a different path."
47
+ end
48
+ else
49
+ # Empty directory - safe to create dataset
50
+ create(path, schema: schema)
51
+ end
21
52
  else
53
+ # Path doesn't exist - create new dataset
22
54
  create(path, schema: schema)
23
55
  end
24
56
  end
@@ -62,8 +94,16 @@ module Lancelot
62
94
  count_rows
63
95
  end
64
96
 
65
- alias_method :count, :size
66
97
  alias_method :length, :size
98
+
99
+ # Override Enumerable's count to use our efficient count_rows when no block given
100
+ def count(&block)
101
+ if block_given?
102
+ super(&block) # Use Enumerable's count with block
103
+ else
104
+ count_rows # Use our efficient count without block
105
+ end
106
+ end
67
107
 
68
108
  def all
69
109
  scan_all
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lancelot
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lancelot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Petersen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-21 00:00:00.000000000 Z
11
+ date: 2025-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys
@@ -111,6 +111,8 @@ files:
111
111
  - LICENSE.txt
112
112
  - README.md
113
113
  - Rakefile
114
+ - docs/assets/lancelot-wide.png
115
+ - docs/assets/lancelot.png
114
116
  - examples/basic_usage.rb
115
117
  - examples/full_text_search.rb
116
118
  - examples/idempotent_create.rb
@@ -129,13 +131,13 @@ files:
129
131
  - lib/lancelot/rank_fusion.rb
130
132
  - lib/lancelot/version.rb
131
133
  - sig/lancelot.rbs
132
- homepage: https://github.com/cpetersen/lancelot
134
+ homepage: https://github.com/scientist-labs/lancelot
133
135
  licenses:
134
136
  - MIT
135
137
  metadata:
136
- homepage_uri: https://github.com/cpetersen/lancelot
137
- source_code_uri: https://github.com/cpetersen/lancelot
138
- changelog_uri: https://github.com/cpetersen/lancelot/blob/main/CHANGELOG.md
138
+ homepage_uri: https://github.com/scientist-labs/lancelot
139
+ source_code_uri: https://github.com/scientist-labs/lancelot
140
+ changelog_uri: https://github.com/scientist-labs/lancelot/blob/main/CHANGELOG.md
139
141
  post_install_message:
140
142
  rdoc_options: []
141
143
  require_paths: