|
| 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 |
0 commit comments