Skip to content

Commit

Permalink
Make model name field mandatory in inference structures (qdrant#5431)
Browse files Browse the repository at this point in the history
* Make model name field mandatory in inference structures

* fix batch tests
  • Loading branch information
joein authored and generall committed Nov 18, 2024
1 parent 7629faa commit 609d5c5
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions docs/grpc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ The JSON representation for `Value` is a JSON value.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| text | [string](#string) | | Text of the document |
| model | [string](#string) | optional | Model name |
| model | [string](#string) | | Model name |
| options | [Document.OptionsEntry](#qdrant-Document-OptionsEntry) | repeated | Model options |


Expand Down Expand Up @@ -2814,7 +2814,7 @@ Additionally, the first and last points of each GeoLineString must be the same.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| image | [Value](#qdrant-Value) | | Image data, either base64 encoded or URL |
| model | [string](#string) | optional | Model name |
| model | [string](#string) | | Model name |
| options | [Image.OptionsEntry](#qdrant-Image-OptionsEntry) | repeated | Model options |


Expand Down Expand Up @@ -2847,7 +2847,7 @@ Additionally, the first and last points of each GeoLineString must be the same.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| object | [Value](#qdrant-Value) | | Object to infer |
| model | [string](#string) | optional | Model name |
| model | [string](#string) | | Model name |
| options | [InferenceObject.OptionsEntry](#qdrant-InferenceObject-OptionsEntry) | repeated | Model options |


Expand Down
14 changes: 7 additions & 7 deletions docs/redoc/master/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9943,6 +9943,7 @@
"description": "WARN: Work-in-progress, unimplemented\n\nText document for embedding. Requires inference infrastructure, unimplemented.",
"type": "object",
"required": [
"model",
"text"
],
"properties": {
Expand All @@ -9952,8 +9953,7 @@
},
"model": {
"description": "Name of the model used to generate the vector List of available models depends on a provider",
"type": "string",
"nullable": true
"type": "string"
},
"options": {
"description": "Parameters for the model Values of the parameters are model-specific",
Expand All @@ -9967,16 +9967,16 @@
"description": "WARN: Work-in-progress, unimplemented\n\nImage object for embedding. Requires inference infrastructure, unimplemented.",
"type": "object",
"required": [
"image"
"image",
"model"
],
"properties": {
"image": {
"description": "Image data: base64 encoded image or an URL"
},
"model": {
"description": "Name of the model used to generate the vector List of available models depends on a provider",
"type": "string",
"nullable": true
"type": "string"
},
"options": {
"description": "Parameters for the model Values of the parameters are model-specific",
Expand All @@ -9990,6 +9990,7 @@
"description": "WARN: Work-in-progress, unimplemented\n\nCustom object for embedding. Requires inference infrastructure, unimplemented.",
"type": "object",
"required": [
"model",
"object"
],
"properties": {
Expand All @@ -9998,8 +9999,7 @@
},
"model": {
"description": "Name of the model used to generate the vector List of available models depends on a provider",
"type": "string",
"nullable": true
"type": "string"
},
"options": {
"description": "Parameters for the model Values of the parameters are model-specific",
Expand Down
6 changes: 3 additions & 3 deletions lib/api/src/grpc/proto/points.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ message SparseIndices {

message Document {
string text = 1; // Text of the document
optional string model = 3; // Model name
string model = 3; // Model name
map<string, Value> options = 4; // Model options
}

message Image {
Value image = 1; // Image data, either base64 encoded or URL
optional string model = 2; // Model name
string model = 2; // Model name
map<string, Value> options = 3; // Model options
}

message InferenceObject {
Value object = 1; // Object to infer
optional string model = 2; // Model name
string model = 2; // Model name
map<string, Value> options = 3; // Model options
}

Expand Down
12 changes: 6 additions & 6 deletions lib/api/src/grpc/qdrant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3835,8 +3835,8 @@ pub struct Document {
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
/// Model name
#[prost(string, optional, tag = "3")]
pub model: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, tag = "3")]
pub model: ::prost::alloc::string::String,
/// Model options
#[prost(map = "string, message", tag = "4")]
pub options: ::std::collections::HashMap<::prost::alloc::string::String, Value>,
Expand All @@ -3849,8 +3849,8 @@ pub struct Image {
#[prost(message, optional, tag = "1")]
pub image: ::core::option::Option<Value>,
/// Model name
#[prost(string, optional, tag = "2")]
pub model: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, tag = "2")]
pub model: ::prost::alloc::string::String,
/// Model options
#[prost(map = "string, message", tag = "3")]
pub options: ::std::collections::HashMap<::prost::alloc::string::String, Value>,
Expand All @@ -3863,8 +3863,8 @@ pub struct InferenceObject {
#[prost(message, optional, tag = "1")]
pub object: ::core::option::Option<Value>,
/// Model name
#[prost(string, optional, tag = "2")]
pub model: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, tag = "2")]
pub model: ::prost::alloc::string::String,
/// Model options
#[prost(map = "string, message", tag = "3")]
pub options: ::std::collections::HashMap<::prost::alloc::string::String, Value>,
Expand Down
6 changes: 3 additions & 3 deletions lib/api/src/rest/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub struct Document {
pub text: String,
/// Name of the model used to generate the vector
/// List of available models depends on a provider
pub model: Option<String>,
pub model: String,
#[serde(flatten)]
pub options: Options,
}
Expand All @@ -185,7 +185,7 @@ pub struct Image {
pub image: Value,
/// Name of the model used to generate the vector
/// List of available models depends on a provider
pub model: Option<String>,
pub model: String,
/// Parameters for the model
/// Values of the parameters are model-specific
#[serde(flatten)]
Expand All @@ -202,7 +202,7 @@ pub struct InferenceObject {
pub object: Value,
/// Name of the model used to generate the vector
/// List of available models depends on a provider
pub model: Option<String>,
pub model: String,
/// Parameters for the model
/// Values of the parameters are model-specific
#[serde(flatten)]
Expand Down
10 changes: 5 additions & 5 deletions src/common/inference/batch_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@ mod tests {
fn create_test_document(text: &str) -> Document {
Document {
text: text.to_string(),
model: Some("test-model".to_string()),
model: "test-model".to_string(),
options: Default::default(),
}
}

fn create_test_image(url: &str) -> Image {
Image {
image: json!({"data": url.to_string()}),
model: Some("test-model".to_string()),
model: "test-model".to_string(),
options: Default::default(),
}
}

fn create_test_object(data: &str) -> InferenceObject {
InferenceObject {
object: json!({"data": data}),
model: Some("test-model".to_string()),
model: "test-model".to_string(),
options: Default::default(),
}
}
Expand Down Expand Up @@ -329,8 +329,8 @@ mod tests {

let mut doc1 = create_test_document("same");
let mut doc2 = create_test_document("same");
doc1.model = Some("model1".to_string());
doc2.model = Some("model2".to_string());
doc1.model = "model1".to_string();
doc2.model = "model2".to_string();

batch.add(InferenceData::Document(doc1));
batch.add(InferenceData::Document(doc2));
Expand Down
10 changes: 5 additions & 5 deletions src/common/inference/batch_processing_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,23 @@ mod tests {
fn create_test_document(text: &str) -> Document {
Document {
text: text.to_string(),
model: Some("test-model".to_string()),
model: "test-model".to_string(),
options: Default::default(),
}
}

fn create_test_image(url: &str) -> Image {
Image {
image: json!({"data": url.to_string()}),
model: Some("test-model".to_string()),
model: "test-model".to_string(),
options: Default::default(),
}
}

fn create_test_object(data: &str) -> InferenceObject {
InferenceObject {
object: json!({"data": data}),
model: Some("test-model".to_string()),
model: "test-model".to_string(),
options: Default::default(),
}
}
Expand Down Expand Up @@ -341,8 +341,8 @@ mod tests {

let mut doc1 = create_test_document("same");
let mut doc2 = create_test_document("same");
doc1.model = Some("model1".to_string());
doc2.model = Some("model2".to_string());
doc1.model = "model1".to_string();
doc2.model = "model2".to_string();

batch.add(InferenceData::Document(doc1));
batch.add(InferenceData::Document(doc2));
Expand Down
6 changes: 3 additions & 3 deletions src/common/inference/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl From<InferenceData> for InferenceInput {
InferenceInput {
data: Value::String(text),
data_type: DOCUMENT_DATA_TYPE.to_string(),
model: model.unwrap_or_default(),
model: model.to_string(),
options: options.options,
}
}
Expand All @@ -95,7 +95,7 @@ impl From<InferenceData> for InferenceInput {
InferenceInput {
data: image,
data_type: IMAGE_DATA_TYPE.to_string(),
model: model.unwrap_or_default(),
model: model.to_string(),
options: options.options,
}
}
Expand All @@ -108,7 +108,7 @@ impl From<InferenceData> for InferenceInput {
InferenceInput {
data: object,
data_type: OBJECT_DATA_TYPE.to_string(),
model: model.unwrap_or_default(),
model: model.to_string(),
options: options.options,
}
}
Expand Down

0 comments on commit 609d5c5

Please sign in to comment.