This commit is contained in:
2025-03-24 06:44:39 +01:00
parent 0df10f5cb3
commit 598b312140
371 changed files with 8238 additions and 9082 deletions

View File

@@ -1,226 +0,0 @@
module qdrant
import freeflowuniverse.herolib.core.httpconnection
import json
// Configuration of the collection
pub struct CollectionConfig {
pub mut:
params CollectionParams // Collection parameters
hnsw_config HNSWConfig // HNSW configuration
optimizer_config OptimizerConfig // Optimizer configuration
wal_config WALConfig // WAL configuration
quantization_config ?QuantizationConfig // Optional quantization configuration, Nullable field
strict_mode_config StrictModeConfig // Strict mode configuration
}
// Parameters of the collection
pub struct CollectionParams {
pub mut:
vectors VectorConfig // Vector configuration
shard_number int // Number of shards
replication_factor int // Replication factor
write_consistency_factor int // Write consistency factor
on_disk_payload bool // On-disk payload
}
// Vector configuration
pub struct VectorConfig {
pub mut:
size int // Size of the vectors
distance string // Distance function
}
// HNSW (Hierarchical Navigable Small World) configuration
pub struct HNSWConfig {
pub mut:
m int // Number of neighbors
ef_construct int // Number of neighbors
full_scan_threshold int // Full scan threshold
max_indexing_threads int // Maximum indexing threads
on_disk bool // On-disk storage
}
// Optimizer configuration
pub struct OptimizerConfig {
pub mut:
deleted_threshold f64 // Deleted threshold
vacuum_min_vector_number int // Minimum vector number
default_segment_number int // Default segment number
max_segment_size ?int // Nullable field
memmap_threshold ?int // Nullable field
indexing_threshold int // Indexing threshold
flush_interval_sec int // Flush interval
max_optimization_threads ?int // Nullable field
}
// Write-Ahead Log (WAL) configuration
pub struct WALConfig {
pub mut:
wal_capacity_mb int // WAL capacity in megabytes
wal_segments_ahead int // WAL segments ahead
}
// Quantization configuration (nullable)
pub struct QuantizationConfig {
pub mut:
scalar ?ScalarQuantization // Nullable field
}
// Scalar quantization configuration
pub struct ScalarQuantization {
pub mut:
typ string @[json: 'type'] // Quantization type
}
// Strict mode configuration
pub struct StrictModeConfig {
pub mut:
enabled bool // Enabled
}
// Result field containing detailed information about the collection
pub struct GetCollectionResponse {
pub mut:
status string // Status
optimizer_status string // Optimizer status
indexed_vectors_count int // Indexed vectors count
points_count int // Points count
segments_count int // Segments count
config CollectionConfig // Collection configuration
payload_schema map[string]string // Payload schema
}
// Get a collection arguments
@[params]
pub struct GetCollectionParams {
pub mut:
collection_name string @[required] // Name of the collection
}
// Get a collection
pub fn (mut self QDrantClient) get_collection(params GetCollectionParams) !QDrantResponse[GetCollectionResponse] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .get
prefix: '/collections/${params.collection_name}'
}
mut response := http_conn.get_json(req)!
return json.decode(QDrantResponse[GetCollectionResponse], response)!
}
// Create a collection arguments
@[params]
pub struct CreateCollectionParams {
pub mut:
collection_name string @[required] // Name of the collection
size int @[required] // Size of the vectors
distance string @[required] // Distance function
}
// Create a collection
pub fn (mut self QDrantClient) create_collection(params CreateCollectionParams) !QDrantResponse[bool] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .put
prefix: '/collections/${params.collection_name}'
data: json.encode(VectorConfig{
size: params.size
distance: params.distance
})
}
mut response := http_conn.send(req)!
if response.code >= 400 {
error_ := json.decode(QDrantErrorResponse, response.data)!
return error('Error creating collection: ' + error_.status.error)
}
return json.decode(QDrantResponse[bool], response.data)!
}
// Delete a collection arguments
@[params]
pub struct DeleteCollectionParams {
pub mut:
collection_name string @[required] // Name of the collection
}
// Delete a collection
pub fn (mut self QDrantClient) delete_collection(params DeleteCollectionParams) !QDrantResponse[bool] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .delete
prefix: '/collections/${params.collection_name}'
}
mut response := http_conn.send(req)!
if response.code >= 400 {
error_ := json.decode(QDrantErrorResponse, response.data)!
return error('Error deleting collection: ' + error_.status.error)
}
return json.decode(QDrantResponse[bool], response.data)!
}
// Get a collection arguments
@[params]
pub struct ListCollectionParams {
collections []CollectionNameParams // List of collection names
}
// Get a collection arguments
@[params]
pub struct CollectionNameParams {
pub mut:
collection_name string @[json: 'name'; required] // Name of the collection
}
// List a collection
pub fn (mut self QDrantClient) list_collections() !QDrantResponse[ListCollectionParams] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .get
prefix: '/collections'
}
mut response := http_conn.send(req)!
if response.code >= 400 {
error_ := json.decode(QDrantErrorResponse, response.data)!
return error('Error listing collection: ' + error_.status.error)
}
return json.decode(QDrantResponse[ListCollectionParams], response.data)!
}
// Check collection existence
pub struct CollectionExistenceResponse {
pub mut:
exists bool // Collection existence
}
// Check collection existence
@[params]
pub struct CollectionExistenceParams {
pub mut:
collection_name string @[json: 'name'; required] // Name of the collection
}
// Check collection existence
pub fn (mut self QDrantClient) is_collection_exists(params CollectionExistenceParams) !QDrantResponse[CollectionExistenceResponse] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .get
prefix: '/collections/${params.collection_name}/exists'
}
mut response := http_conn.send(req)!
if response.code >= 400 {
error_ := json.decode(QDrantErrorResponse, response.data)!
return error('Error checking collection: ' + error_.status.error)
}
return json.decode(QDrantResponse[CollectionExistenceResponse], response.data)!
}

View File

@@ -1,88 +0,0 @@
module qdrant
import freeflowuniverse.herolib.core.httpconnection
import json
import rand
// Retrieves all details from multiple points.
@[params]
pub struct RetrievePointsParams {
pub mut:
ids []int @[json: 'ids'; required] // Look for points with ids
collection_name string @[json: 'collection_name'; required] // Name of the collection
shard_key ?string // Specify in which shards to look for the points, if not specified - look in all shards
with_payload ?bool // Select which payload to return with the response. Default is true.
with_vectors ?bool // Options for specifying which vectors to include into response. Default is false.
}
pub struct RetrievePointsResponse {
pub mut:
id int // Type, used for specifying point ID in user interface
payload map[string]string // Payload - values assigned to the point
vector []f64 // Vector of the point
shard_id string // Shard name
order_value f64 // Order value
}
// Retrieves all details from multiple points.
pub fn (mut self QDrantClient) retrieve_points(params RetrievePointsParams) !QDrantResponse[RetrievePointsResponse] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .post
prefix: '/collections/${params.collection_name}/points'
data: json.encode(params)
}
mut response := http_conn.send(req)!
if response.code >= 400 {
error_ := json.decode(QDrantErrorResponse, response.data)!
return error('Error retrieving points: ' + error_.status.error)
}
return json.decode(QDrantResponse[RetrievePointsResponse], response.data)!
}
// Parameters for upserting points into a Qdrant collection.
@[params]
pub struct UpsertPointsParams {
pub mut:
collection_name string @[json: 'collection_name'; required] // Name of the collection
points []Point @[json: 'points'; required] // List of points to upsert
shard_key ?string // Optional shard key for sharding
}
// Represents a single point to be upserted.
pub struct Point {
pub mut:
id string = rand.uuid_v4() @[json: 'id'; required] // Point ID (can be string or integer, serialized as string)
payload map[string]string @[json: 'payload'] // Payload key-value pairs (optional)
vector []f64 @[json: 'vector'; required] // Vector data for the point
}
// Response structure for the upsert points operation.
pub struct UpsertPointsResponse {
pub mut:
status string @[json: 'status']
operation_id int @[json: 'operation_id']
}
// Upserts points into a Qdrant collection.
// Performs insert + update actions on specified points. Any point with an existing {id} will be overwritten.
pub fn (mut self QDrantClient) upsert_points(params UpsertPointsParams) !QDrantResponse[UpsertPointsResponse] {
mut http_conn := self.httpclient()!
req := httpconnection.Request{
method: .put
prefix: '/collections/${params.collection_name}/points'
data: json.encode(params)
}
mut response := http_conn.send(req)!
if response.code >= 400 {
error_ := json.decode(QDrantErrorResponse, response.data)!
return error('Error upserting points: ' + error_.status.error)
}
return json.decode(QDrantResponse[UpsertPointsResponse], response.data)!
}

View File

@@ -1,425 +0,0 @@
module qdrant
import freeflowuniverse.herolib.core.httpconnection
<<<<<<< HEAD
=======
import json
>>>>>>> development_actions007
// QDrant usage
pub struct QDrantUsage {
pub mut:
cpu int // CPU usage
io_read int // I/O read usage
io_write int // I/O write usage
}
// Top-level response structure
pub struct QDrantResponse[T] {
pub mut:
usage QDrantUsage // Usage information
result T // The result
status string // Response status
time f64 // Response time
}
pub struct QDrantErrorResponse {
pub mut:
status QDrantError // Response status
time f64 // Response time
}
// Qdrant error response
pub struct QDrantError {
pub mut:
error string // Error message
}
// httpclient creates a new HTTP connection to the Qdrant API
fn (mut self QDrantClient) httpclient() !&httpconnection.HTTPConnection {
mut http_conn := httpconnection.new(
name: 'Qdrant_vclient'
url: self.url
)!
// Add authentication header if API key is provided
if self.secret.len > 0 {
<<<<<<< HEAD
http_conn.default_header.add_custom('api-key', self.secret)!
=======
http_conn.default_header.add_custom('api_key', self.secret)!
>>>>>>> development_actions007
}
return http_conn
}
<<<<<<< HEAD
=======
// Collections API
@[params]
pub struct CreateCollectionParams {
pub mut:
collection_name string @[required]
vectors VectorsConfig @[required]
shard_number ?int
replication_factor ?int
write_consistency_factor ?int
on_disk_payload ?bool
hnsw_config ?HnswConfig
optimizers_config ?OptimizersConfig
wal_config ?WalConfig
quantization_config ?QuantizationConfig
init_from ?InitFrom
timeout ?int
}
// Create a new collection
pub fn (mut q QdrantClient) create_collection(params CreateCollectionParams) !bool {
mut collection_params := CollectionParams{
vectors: params.vectors
}
if v := params.shard_number {
collection_params.shard_number = v
}
if v := params.replication_factor {
collection_params.replication_factor = v
}
if v := params.write_consistency_factor {
collection_params.write_consistency_factor = v
}
if v := params.on_disk_payload {
collection_params.on_disk_payload = v
}
if v := params.hnsw_config {
collection_params.hnsw_config = v
}
if v := params.optimizers_config {
collection_params.optimizers_config = v
}
if v := params.wal_config {
collection_params.wal_config = v
}
if v := params.quantization_config {
collection_params.quantization_config = v
}
if v := params.init_from {
collection_params.init_from = v
}
mut query_params := map[string]string{}
if v := params.timeout {
query_params['timeout'] = v.str()
}
req := httpconnection.Request{
method: .put
prefix: 'collections/${params.collection_name}'
dataformat: .json
data: json.encode(collection_params)
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
result := json.decode(OperationResponse, response.data)!
return result.result
}
@[params]
pub struct ListCollectionsParams {
pub mut:
timeout ?int
}
// List all collections
pub fn (mut q QdrantClient) list_collections(params ListCollectionsParams) !CollectionsResponse {
mut query_params := map[string]string{}
if v := params.timeout {
query_params['timeout'] = v.str()
}
req := httpconnection.Request{
method: .get
prefix: 'collections'
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return json.decode(CollectionsResponse, response.data)!
}
@[params]
pub struct DeleteCollectionParams {
pub mut:
collection_name string @[required]
timeout ?int
}
// Delete a collection
pub fn (mut q QdrantClient) delete_collection(params DeleteCollectionParams) !bool {
mut query_params := map[string]string{}
if v := params.timeout {
query_params['timeout'] = v.str()
}
req := httpconnection.Request{
method: .delete
prefix: 'collections/${params.collection_name}'
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
result := json.decode(OperationResponse, response.data)!
return result.result
}
@[params]
pub struct GetCollectionParams {
pub mut:
collection_name string @[required]
timeout ?int
}
// Get collection info
pub fn (mut q QdrantClient) get_collection(params GetCollectionParams) !CollectionInfo {
mut query_params := map[string]string{}
if v := params.timeout {
query_params['timeout'] = v.str()
}
req := httpconnection.Request{
method: .get
prefix: 'collections/${params.collection_name}'
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
result := json.decode(CollectionInfoResponse, response.data)!
return result.result
}
// Points API
@[params]
pub struct UpsertPointsParams {
pub mut:
collection_name string @[required]
points []PointStruct @[required]
wait ?bool
ordering ?WriteOrdering
}
// Upsert points
pub fn (mut q QdrantClient) upsert_points(params UpsertPointsParams) !PointsOperationResponse {
mut query_params := map[string]string{}
if v := params.wait {
query_params['wait'] = v.str()
}
mut request_body := map[string]string{}
request_body['points'] = json.encode(params.points)
if v := params.ordering {
request_body['ordering'] = json.encode(v)
}
req := httpconnection.Request{
method: .put
prefix: 'collections/${params.collection_name}/points'
dataformat: .json
data: json.encode(request_body)
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return json.decode(PointsOperationResponse, response.data)!
}
@[params]
pub struct DeletePointsParams {
pub mut:
collection_name string @[required]
points_selector PointsSelector @[required]
wait ?bool
ordering ?WriteOrdering
}
// Delete points
pub fn (mut q QdrantClient) delete_points(params DeletePointsParams) !PointsOperationResponse {
mut query_params := map[string]string{}
if v := params.wait {
query_params['wait'] = v.str()
}
mut request_body := map[string]string{}
if params.points_selector.points != none {
request_body['points'] = params.points_selector.points.str()
} else if params.points_selector.filter != none {
request_body['filter'] = params.points_selector.filter.str()
}
if v := params.ordering {
request_body['ordering'] = v.str()
}
req := httpconnection.Request{
method: .post
prefix: 'collections/${params.collection_name}/points/delete'
dataformat: .json
data: json.encode(request_body)
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return json.decode(PointsOperationResponse, response.data)!
}
@[params]
pub struct GetPointParams {
pub mut:
collection_name string @[required]
id string @[required]
with_payload ?WithPayloadSelector
with_vector ?WithVector
}
// Get a point by ID
pub fn (mut q QdrantClient) get_point(params GetPointParams) !GetPointResponse {
mut query_params := map[string]string{}
if v := params.with_payload {
query_params['with_payload'] = json.encode(v)
}
if v := params.with_vector {
query_params['with_vector'] = json.encode(v)
}
req := httpconnection.Request{
method: .get
prefix: 'collections/${params.collection_name}/points/${params.id}'
params: query_params
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return json.decode(GetPointResponse, response.data)!
}
@[params]
pub struct SearchParams {
pub mut:
collection_name string @[required]
vector []f32 @[required]
limit int = 10
filter ?Filter
params ?SearchParamsConfig
with_payload ?WithPayloadSelector
with_vector ?WithVector
score_threshold ?f32
}
// Search for points
pub fn (mut q QdrantClient) search(params SearchParams) !SearchResponse {
// Create a struct to serialize to JSON
struct SearchRequest {
pub mut:
vector []f32
limit int
filter ?Filter
params ?SearchParamsConfig
with_payload ?WithPayloadSelector
with_vector ?WithVector
score_threshold ?f32
}
mut request := SearchRequest{
vector: params.vector
limit: params.limit
}
if v := params.filter {
request.filter = v
}
if v := params.params {
request.params = v
}
if v := params.with_payload {
request.with_payload = v
}
if v := params.with_vector {
request.with_vector = v
}
if v := params.score_threshold {
request.score_threshold = v
}
req := httpconnection.Request{
method: .post
prefix: 'collections/${params.collection_name}/points/search'
dataformat: .json
data: json.encode(request)
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return json.decode(SearchResponse, response.data)!
}
// Service API
// Get Qdrant service info
pub fn (mut q QdrantClient) get_service_info() !ServiceInfoResponse {
req := httpconnection.Request{
method: .get
prefix: ''
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return json.decode(ServiceInfoResponse, response.data)!
}
// Check Qdrant health
pub fn (mut q QdrantClient) health_check() !bool {
req := httpconnection.Request{
method: .get
prefix: 'healthz'
}
mut httpclient := q.httpclient()!
response := httpclient.send(req)!
return response.code == 200
}
>>>>>>> development_actions007

View File

@@ -1 +0,0 @@
module qdrant

View File

@@ -35,363 +35,3 @@ pub fn heroscript_loads(heroscript string) !QDrantClient {
mut obj := encoderhero.decode[QDrantClient](heroscript)!
return obj
}
// // Base response structure
// pub struct BaseResponse {
// pub mut:
// time f32
// status string
// }
// // Operation response
// pub struct OperationResponse {
// pub mut:
// time f32
// status string
// result bool
// }
// // Collections response
// pub struct CollectionsResponse {
// pub mut:
// time f32
// status string
// result []string
// }
// // Collection info response
// pub struct CollectionInfoResponse {
// pub mut:
// time f32
// status string
// result CollectionInfo
// }
// // Collection info
// pub struct CollectionInfo {
// pub mut:
// status string
// optimizer_status OptimizersStatus
// vectors_count u64
// indexed_vectors_count ?u64
// points_count u64
// segments_count u64
// config CollectionConfig
// payload_schema map[string]PayloadIndexInfo
// }
// // Optimizers status
// pub struct OptimizersStatus {
// pub mut:
// status string
// }
// // Collection config
// pub struct CollectionConfig {
// pub mut:
// params CollectionParams
// hnsw_config ?HnswConfig
// optimizer_config ?OptimizersConfig
// wal_config ?WalConfig
// quantization_config ?QuantizationConfig
// }
// // Collection params
// pub struct CollectionParams {
// pub mut:
// vectors VectorsConfig
// shard_number ?int
// replication_factor ?int
// write_consistency_factor ?int
// on_disk_payload ?bool
// hnsw_config ?HnswConfig
// optimizers_config ?OptimizersConfig
// wal_config ?WalConfig
// quantization_config ?QuantizationConfig
// init_from ?InitFrom
// }
// // Vectors config
// pub struct VectorsConfig {
// pub mut:
// size int
// distance Distance
// hnsw_config ?HnswConfig
// quantization_config ?QuantizationConfig
// on_disk ?bool
// }
// // Distance type
// pub enum Distance {
// cosine
// euclid
// dot
// }
// // Convert Distance enum to string
// pub fn (d Distance) str() string {
// return match d {
// .cosine { 'cosine' }
// .euclid { 'euclid' }
// .dot { 'dot' }
// }
// }
// // HNSW config
// pub struct HnswConfig {
// pub mut:
// m int
// ef_construct int
// full_scan_threshold ?int
// max_indexing_threads ?int
// on_disk ?bool
// payload_m ?int
// }
// // Optimizers config
// pub struct OptimizersConfig {
// pub mut:
// deleted_threshold f32
// vacuum_min_vector_number int
// default_segment_number int
// max_segment_size ?int
// memmap_threshold ?int
// indexing_threshold ?int
// flush_interval_sec ?int
// max_optimization_threads ?int
// }
// // WAL config
// pub struct WalConfig {
// pub mut:
// wal_capacity_mb ?int
// wal_segments_ahead ?int
// }
// // Quantization config
// pub struct QuantizationConfig {
// pub mut:
// scalar ?ScalarQuantization
// product ?ProductQuantization
// binary ?BinaryQuantization
// }
// // Scalar quantization
// pub struct ScalarQuantization {
// pub mut:
// type_ string
// quantile ?f32
// always_ram ?bool
// }
// // Product quantization
// pub struct ProductQuantization {
// pub mut:
// compression string
// always_ram ?bool
// }
// // Binary quantization
// pub struct BinaryQuantization {
// pub mut:
// binary bool
// always_ram ?bool
// }
// // Init from
// pub struct InitFrom {
// pub mut:
// collection string
// shard ?int
// }
// // Payload index info
// pub struct PayloadIndexInfo {
// pub mut:
// data_type string
// params ?map[string]string
// points int
// }
// // Points operation response
// pub struct PointsOperationResponse {
// pub mut:
// time f32
// status string
// result OperationInfo
// }
// // Operation info
// pub struct OperationInfo {
// pub mut:
// operation_id int
// status string
// }
// // Point struct
// pub struct PointStruct {
// pub mut:
// id string
// vector []f32
// payload ?map[string]string
// }
// // Points selector
// pub struct PointsSelector {
// pub mut:
// points ?[]string
// filter ?Filter
// }
// // Filter
// pub struct Filter {
// pub mut:
// must ?[]Condition
// must_not ?[]Condition
// should ?[]Condition
// }
// // Filter is serialized directly to JSON
// // Condition interface
// pub interface Condition {}
// // Field condition
// pub struct FieldCondition {
// pub mut:
// key string
// match ?string @[json: match]
// match_integer ?int @[json: match]
// match_float ?f32 @[json: match]
// match_bool ?bool @[json: match]
// range ?Range
// geo_bounding_box ?GeoBoundingBox
// geo_radius ?GeoRadius
// values_count ?ValuesCount
// }
// // FieldCondition is serialized directly to JSON
// // Range
// pub struct Range {
// pub mut:
// lt ?f32
// gt ?f32
// gte ?f32
// lte ?f32
// }
// // Range is serialized directly to JSON
// // GeoBoundingBox
// pub struct GeoBoundingBox {
// pub mut:
// top_left GeoPoint
// bottom_right GeoPoint
// }
// // GeoBoundingBox is serialized directly to JSON
// // GeoPoint
// pub struct GeoPoint {
// pub mut:
// lon f32
// lat f32
// }
// // GeoPoint is serialized directly to JSON
// // GeoRadius
// pub struct GeoRadius {
// pub mut:
// center GeoPoint
// radius f32
// }
// // GeoRadius is serialized directly to JSON
// // ValuesCount
// pub struct ValuesCount {
// pub mut:
// lt ?int
// gt ?int
// gte ?int
// lte ?int
// }
// // ValuesCount is serialized directly to JSON
// // WithPayloadSelector
// pub struct WithPayloadSelector {
// pub mut:
// include ?[]string
// exclude ?[]string
// }
// // WithPayloadSelector is serialized directly to JSON
// // WithVector
// pub struct WithVector {
// pub mut:
// include ?[]string
// }
// // WithVector is serialized directly to JSON
// // Get point response
// pub struct GetPointResponse {
// pub mut:
// time f32
// status string
// result ?PointStruct
// }
// // Search params configuration
// pub struct SearchParamsConfig {
// pub mut:
// hnsw_ef ?int
// exact ?bool
// }
// // SearchParamsConfig is serialized directly to JSON
// // Search response
// pub struct SearchResponse {
// pub mut:
// time f32
// status string
// result []ScoredPoint
// }
// // Scored point
// pub struct ScoredPoint {
// pub mut:
// id string
// version int
// score f32
// payload ?map[string]string
// vector ?[]f32
// }
// // Write ordering
// pub struct WriteOrdering {
// pub mut:
// type_ string
// }
// // WriteOrdering is serialized directly to JSON
// // Service info response
// pub struct ServiceInfoResponse {
// pub mut:
// time f32
// status string
// result ServiceInfo
// }
// // Service info
// pub struct ServiceInfo {
// pub mut:
// version string
// commit ?string
// }