Skip to content

Commit 7acda1d

Browse files
authored
feat: update lumina lib to v0.3.0-rc1 (alibaba#372)
1 parent 1df3fe0 commit 7acda1d

43 files changed

Lines changed: 1330 additions & 252 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/paimon/global_index/lumina/lumina_api_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
#include "lumina/api/LuminaBuilder.h"
17+
#include "lumina/api/LuminaSearcher.h"
1718
#include "lumina/core/Constants.h"
1819
#include "lumina/core/Status.h"
1920
#include "lumina/core/Types.h"
@@ -133,7 +134,7 @@ class LuminaInterfaceTest : public ::testing::Test {
133134
ASSERT_GT(paimon_pool->MaxMemoryUsage(), 0);
134135
}
135136

136-
void CheckResult(const std::vector<::lumina::api::LuminaSearcher::SearchHit>& search_result,
137+
void CheckResult(const std::vector<::lumina::api::SearchHit>& search_result,
137138
const std::vector<::lumina::core::vector_id_t>& expected_row_ids,
138139
const std::vector<float>& expected_distances) const {
139140
ASSERT_EQ(search_result.size(), expected_row_ids.size());

src/paimon/global_index/lumina/lumina_global_index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vector>
2424

2525
#include "arrow/api.h"
26+
#include "lumina/api/LuminaSearcher.h"
2627
#include "lumina/api/Options.h"
2728
#include "lumina/extensions/SearchWithFilterExtension.h"
2829
#include "paimon/global_index/bitmap_global_index_result.h"

third_party/lumina/VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
tag: v0.2.2
2-
89ea85ed8ef350455a15e1a2519271007ae15807
1+
tag: v0.3.0-rc1
2+
304227808425be9b2db0ded1e2e43be0ffba42b2

third_party/lumina/include/lumina/api/Dataset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
1718
#pragma once
1819

1920
#include <cstdint>

third_party/lumina/include/lumina/api/Extension.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,41 @@
2222
#include <lumina/api/Query.h>
2323
#include <lumina/core/NoCopyable.h>
2424
#include <lumina/core/Status.h>
25+
#include <memory>
2526
#include <string>
2627
#include <string_view>
27-
#include <unordered_map>
2828
#include <vector>
2929

3030
namespace lumina::api {
3131

3232
// Note: Attach only registers capabilities; the framework does not own extension lifetimes.
3333
// Callers must ensure thread safety and lifetime covers the search/build process.
34-
class ISearchExtension : public core::NoCopyable
34+
class ISearchExtension : public core::NoCopyable, public core::NoMoveable
3535
{
3636
public:
3737
virtual ~ISearchExtension() = default;
3838
virtual std::string_view Name() const noexcept = 0;
3939
};
4040

41-
class IBuildExtension : public core::NoCopyable
41+
class BuilderStatusManager;
42+
43+
class IBuildExtension : public core::NoCopyable, public core::NoMoveable
4244
{
4345
public:
4446
virtual ~IBuildExtension() = default;
4547
virtual std::string_view Name() const noexcept = 0;
48+
49+
/// Called by Impl::Attach() to inject the status manager that the extension
50+
/// uses to coordinate state transitions (e.g., tag insert).
51+
/// Default implementation is a no-op for extensions that don't need it.
52+
virtual void SetBuilderStatusManager(std::shared_ptr<BuilderStatusManager> /*manager*/) noexcept {}
53+
};
54+
55+
class IStreamExtension : public core::NoCopyable, public core::NoMoveable
56+
{
57+
public:
58+
virtual ~IStreamExtension() = default;
59+
virtual std::string_view Name() const noexcept = 0;
4660
};
4761

4862
} // namespace lumina::api

third_party/lumina/include/lumina/api/LuminaBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class LuminaBuilder final : public core::NoCopyable
4646
public:
4747
class Impl;
4848
LuminaBuilder(LuminaBuilder&&) noexcept;
49+
LuminaBuilder& operator=(LuminaBuilder&&) noexcept;
4950
LuminaBuilder(std::unique_ptr<Impl> impl) noexcept;
5051
~LuminaBuilder() noexcept;
5152
// Typical offline build: create a Builder by preset (e.g. "ivf", "diskann", "bruteforce", "demo")

third_party/lumina/include/lumina/api/LuminaSearcher.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <lumina/api/Extension.h>
2121
#include <lumina/api/Options.h>
2222
#include <lumina/api/Query.h>
23+
#include <lumina/api/SearchResult.h>
2324
#include <lumina/core/MemoryResource.h>
2425
#include <lumina/core/NoCopyable.h>
2526
#include <lumina/core/Result.h>
@@ -46,6 +47,7 @@ class LuminaSearcher final : public core::NoCopyable
4647
LuminaSearcher(std::unique_ptr<Impl> impl) noexcept;
4748
// -- Semantics: movable, not copyable --
4849
LuminaSearcher(LuminaSearcher&&) noexcept;
50+
LuminaSearcher& operator=(LuminaSearcher&&) noexcept;
4951
~LuminaSearcher() noexcept;
5052

5153
static core::Result<LuminaSearcher> Create(const SearcherOptions& options) noexcept;
@@ -55,20 +57,13 @@ class LuminaSearcher final : public core::NoCopyable
5557
core::Status Open(const IOOptions& ioOptions) noexcept;
5658
core::Status Open(std::unique_ptr<io::FileReader> reader, const IOOptions& ioOptions) noexcept;
5759

58-
struct SearchHit {
59-
core::vector_id_t id {0};
60-
float distance {0.0f};
61-
};
62-
63-
struct SearchResult {
64-
std::vector<SearchHit> topk;
65-
std::unordered_map<std::string, std::string> searchStats;
66-
};
60+
using SearchHit = api::SearchHit;
61+
using SearchResult = api::SearchResult;
6762

6863
// Index info: basic searcher metadata
6964
struct IndexInfo {
70-
uint64_t count {0}; // Total vectors
71-
core::dimension_t dim {0}; // Vector dimension
65+
uint64_t count {0}; // Total vectors
66+
core::dimension_t dim {0}; // Vector dimension
7267
};
7368

7469
core::Result<SearchResult> Search(const Query& q, const SearchOptions& options) noexcept;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2025-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include <cstddef>
19+
#include <cstdint>
20+
#include <lumina/api/Extension.h>
21+
#include <lumina/api/Options.h>
22+
#include <lumina/api/Query.h>
23+
#include <lumina/api/SearchResult.h>
24+
#include <lumina/core/MemoryResource.h>
25+
#include <lumina/core/NoCopyable.h>
26+
#include <lumina/core/Result.h>
27+
#include <lumina/core/Status.h>
28+
#include <lumina/core/Types.h>
29+
#include <memory>
30+
#include <memory_resource>
31+
#include <string>
32+
#include <unordered_map>
33+
#include <vector>
34+
35+
namespace lumina::api {
36+
37+
// Real-time, in-memory vector indexing. Single-writer Insert, concurrent Search.
38+
class LuminaStreamer final : public core::NoCopyable
39+
{
40+
public:
41+
class Impl;
42+
43+
LuminaStreamer(LuminaStreamer&&) noexcept;
44+
LuminaStreamer& operator=(LuminaStreamer&&) noexcept;
45+
explicit LuminaStreamer(std::unique_ptr<Impl> impl) noexcept;
46+
~LuminaStreamer() noexcept;
47+
48+
static core::Result<LuminaStreamer> Create(const StreamerOptions& options) noexcept;
49+
static core::Result<LuminaStreamer> Create(const StreamerOptions& options,
50+
const core::MemoryResourceConfig& memoryConfig) noexcept;
51+
52+
/** Insert a single vector.
53+
* @param data Non-null pointer to exactly dim floats; returns InvalidArgument if null.
54+
* @param id Caller-assigned identifier. Uniqueness is NOT enforced. */
55+
core::Status Insert(const float* data, core::vector_id_t id) noexcept;
56+
57+
using SearchHit = api::SearchHit;
58+
using SearchResult = api::SearchResult;
59+
60+
// Search is `const`: it does not mutate any observable state of this
61+
// instance. Safe to call concurrently with other Search/GetMeta calls and
62+
// with a single in-flight Insert (see class-level thread-safety note).
63+
core::Result<SearchResult> Search(const Query& q, const SearchOptions& options) const noexcept;
64+
core::Result<SearchResult> Search(const Query& q, const SearchOptions& options,
65+
std::pmr::memory_resource& sessionPool) const noexcept;
66+
67+
struct IndexInfo {
68+
uint64_t count {0}; // Total vectors currently visible to Search.
69+
core::dimension_t dim {0}; // Vector dimension
70+
};
71+
72+
IndexInfo GetMeta() const noexcept;
73+
74+
// -- Extension attach (per instance) --
75+
core::Status Attach(IStreamExtension& ext) noexcept;
76+
77+
private:
78+
std::unique_ptr<Impl> _p;
79+
};
80+
81+
} // namespace lumina::api

third_party/lumina/include/lumina/api/Options.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
#include <algorithm>
2020
#include <cstddef>
2121
#include <cstdint>
22-
#include <lumina/core/Result.h>
23-
#include <lumina/core/Status.h>
24-
#include <lumina/mpl/Concepts.h>
25-
#include <lumina/telemetry/Log.h>
2622
#include <optional>
2723
#include <sstream>
2824
#include <string>
@@ -32,6 +28,12 @@
3228
#include <utility>
3329
#include <variant>
3430

31+
#include <lumina/core/Macro.h>
32+
#include <lumina/core/Result.h>
33+
#include <lumina/core/Status.h>
34+
#include <lumina/mpl/Concepts.h>
35+
#include <lumina/telemetry/Log.h>
36+
3537
namespace lumina::api {
3638

3739
enum class OptionsType {
@@ -40,14 +42,14 @@ enum class OptionsType {
4042
Builder,
4143
Quantizer,
4244
IO,
45+
Streamer,
4346
};
4447

4548
template <OptionsType T>
4649
class Options
4750
{
4851
public:
4952
Options() noexcept = default;
50-
~Options() noexcept = default;
5153

5254
using Value = std::variant<int64_t, double, bool, std::string>;
5355
using Map = std::unordered_map<std::string, Value>;
@@ -122,7 +124,7 @@ class Options
122124
}
123125

124126
// Direct access to all key/value pairs (read-only)
125-
const Map& Values() const noexcept { return _values; }
127+
const Map& Values() const noexcept LUMINA_LIFETIME_BOUND { return _values; }
126128

127129
// Debug string representation of all options
128130
std::string DebugString() const noexcept
@@ -177,6 +179,7 @@ class Options
177179

178180
using SearchOptions = Options<OptionsType::Search>;
179181
using SearcherOptions = Options<OptionsType::Searcher>;
182+
using StreamerOptions = Options<OptionsType::Streamer>;
180183
using BuilderOptions = Options<OptionsType::Builder>;
181184
using QuantizerOptions = Options<OptionsType::Quantizer>;
182185
using IOOptions = Options<OptionsType::IO>;

third_party/lumina/include/lumina/api/OptionsNormalize.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
namespace lumina::api {
2626

2727
// Weakly-typed C++ entry: normalize string->string maps into typed Options.
28-
core::Result<BuilderOptions> NormalizeBuilderOptions(const std::unordered_map<std::string, std::string>& raw);
29-
core::Result<SearcherOptions> NormalizeSearcherOptions(const std::unordered_map<std::string, std::string>& raw);
28+
core::Result<BuilderOptions> NormalizeBuilderOptions(const std::unordered_map<std::string, std::string>& raw) noexcept;
29+
core::Result<SearcherOptions>
30+
NormalizeSearcherOptions(const std::unordered_map<std::string, std::string>& raw) noexcept;
3031
core::Result<SearchOptions> NormalizeSearchOptions(const std::string& indexType,
31-
const std::unordered_map<std::string, std::string>& raw);
32+
const std::unordered_map<std::string, std::string>& raw) noexcept;
3233
// check global search options
33-
core::Status ValidateSearchOptions(const api::SearchOptions& options);
34+
core::Status ValidateSearchOptions(const api::SearchOptions& options) noexcept;
3435

3536
} // namespace lumina::api

0 commit comments

Comments
 (0)