Skip to content

Commit

Permalink
Merge pull request #122 from vitrivr/feature/torchserve
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanopticon authored Nov 26, 2024
2 parents ff198c9 + d2f6d3b commit a44a864
Show file tree
Hide file tree
Showing 20 changed files with 1,197 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ subprojects {
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: version_kotlin
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: version_kotlin
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: version_kotlinx_coroutines
implementation group: 'org.jetbrains.kotlinx', name:'kotlinx-serialization-json', version: version_kotlinx_serialization
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-json', version: version_kotlinx_serialization

/* JUnit 5 */
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: version_junit
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ include 'vitrivr-engine-module-pgvector'
include 'vitrivr-engine-module-features'
include 'vitrivr-engine-module-m3d'
include 'vitrivr-engine-module-fes'
include 'vitrivr-engine-module-torchserve'
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.vitrivr.engine.core.operators.ingest.Extractor
* @author Ralph Gasser
* @version 1.3.0
*/
abstract class AbstractExtractor<C : ContentElement<*>, D : Descriptor<*>> private constructor(
abstract class AbstractExtractor<C : ContentElement<*>, D : Descriptor<*>> constructor(
final override val input: Operator<Retrievable>,
final override val analyser: Analyser<C, D>,
final override val field: Schema.Field<C, D>? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.vitrivr.engine.core.features.bool

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.flow
import org.vitrivr.engine.core.context.QueryContext
import org.vitrivr.engine.core.features.AbstractRetriever
import org.vitrivr.engine.core.model.content.element.ContentElement
import org.vitrivr.engine.core.model.descriptor.scalar.ScalarDescriptor
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.query.bool.BooleanQuery

/**
* A simple [AbstractRetriever] implementation for boolean queries on [ScalarDescriptor]s.
*
* @author Ralph Gasser
* @version 1.0.0
*/
class ScalarBooleanRetriever<C : ContentElement<*>>(field: Schema.Field<C, ScalarDescriptor<*, *>>, query: BooleanQuery, context: QueryContext) : AbstractRetriever<C, ScalarDescriptor<*, *>>(field, query, context) {
override fun toFlow(scope: CoroutineScope) = flow {
val reader = this@ScalarBooleanRetriever.reader
reader.queryAndJoin(this@ScalarBooleanRetriever.query).forEach {
emit(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.vitrivr.engine.core.features.bool

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.flow
import org.vitrivr.engine.core.context.QueryContext
import org.vitrivr.engine.core.features.AbstractRetriever
import org.vitrivr.engine.core.model.content.element.ContentElement
import org.vitrivr.engine.core.model.descriptor.struct.StructDescriptor
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.query.bool.BooleanQuery

/**
* A simple [AbstractRetriever] implementation for boolean queries on [StructDescriptor]s.
*
* @author Ralph Gasser
* @version 1.0.0
*/
class StructBooleanRetriever<C : ContentElement<*>, D : StructDescriptor<*>>(field: Schema.Field<C, D>, query: BooleanQuery, context: QueryContext) : AbstractRetriever<C, D>(field, query, context) {
override fun toFlow(scope: CoroutineScope) = flow {
val reader = this@StructBooleanRetriever.reader
reader.queryAndJoin(this@StructBooleanRetriever.query).forEach {
emit(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ class LabelDescriptor(
override val field: Schema.Field<*, LabelDescriptor>? = null
) : StructDescriptor<LabelDescriptor>(id, retrievableId, SCHEMA, values, field) {
companion object {

const val LABEL_FIELD_NAME = "label"
const val CONFIDENCE_FIELD_NAME = "label"

private val SCHEMA = listOf(
Attribute("label", Type.String),
Attribute("confidence", Type.Float),
Attribute(LABEL_FIELD_NAME, Type.String),
Attribute(CONFIDENCE_FIELD_NAME, Type.Float),
)
}

Expand All @@ -33,7 +37,7 @@ class LabelDescriptor(
label: String,
confidence: Float = 1f,
field: Schema.Field<*, LabelDescriptor>? = null
) : this(id, retrievableId, mapOf("label" to Value.String(label), "confidence" to Value.Float(confidence)), field)
) : this(id, retrievableId, mapOf(LABEL_FIELD_NAME to Value.String(label), CONFIDENCE_FIELD_NAME to Value.Float(confidence)), field)

/** The stored label. */
val label: Value.String by this.values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.*
* Part of the vitrivr-engine's internal type system.
*
* @author Ralph Gasser
* @version 1.0.0
* @version 1.1.0
*/
@Serializable()
sealed interface Value<T> {
Expand Down Expand Up @@ -49,82 +49,93 @@ sealed interface Value<T> {
val type: Type


sealed interface ScalarValue<T>: Value<T>
sealed interface ScalarValue<T> : Value<T>, Comparable<ScalarValue<T>>

@JvmInline
@Serializable
value class String(override val value: kotlin.String) : ScalarValue<kotlin.String> {
override val type: Type
get() = Type.String
override fun compareTo(other: ScalarValue<kotlin.String>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Text(override val value: kotlin.String) : ScalarValue<kotlin.String> {
override val type: Type
get() = Type.Text
override fun compareTo(other: ScalarValue<kotlin.String>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Boolean(override val value: kotlin.Boolean) : ScalarValue<kotlin.Boolean> {
override val type: Type
get() = Type.Boolean
override fun compareTo(other: ScalarValue<kotlin.Boolean>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Byte(override val value: kotlin.Byte) : ScalarValue<kotlin.Byte> {
override val type: Type
get() = Type.Byte
override fun compareTo(other: ScalarValue<kotlin.Byte>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Short(override val value: kotlin.Short) : ScalarValue<kotlin.Short> {
override val type: Type
get() = Type.Short
override fun compareTo(other: ScalarValue<kotlin.Short>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Int(override val value: kotlin.Int) : ScalarValue<kotlin.Int> {
override val type: Type
get() = Type.Int
override fun compareTo(other: ScalarValue<kotlin.Int>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Long(override val value: kotlin.Long) : ScalarValue<kotlin.Long> {
override val type: Type
get() = Type.Long
override fun compareTo(other: ScalarValue<kotlin.Long>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Float(override val value: kotlin.Float) : ScalarValue<kotlin.Float> {
override val type: Type
get() = Type.Float
override fun compareTo(other: ScalarValue<kotlin.Float>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable
value class Double(override val value: kotlin.Double) : ScalarValue<kotlin.Double> {
override val type: Type
get() = Type.Double
override fun compareTo(other: ScalarValue<kotlin.Double>) = this.value.compareTo(other.value)
}

@JvmInline
@Serializable(with = DateTimeSerializer::class)
value class DateTime(override val value: Date) : ScalarValue<Date> {
override val type: Type
get() = Type.Datetime
override fun compareTo(other: ScalarValue<Date>) = this.value.compareTo(other.value)
}

@JvmInline
value class UUIDValue(override val value: UUID) : ScalarValue<UUID> {
override val type: Type
get() = Type.UUID
override fun compareTo(other: ScalarValue<UUID>) = this.value.compareTo(other.value)
}

/**
Expand Down
108 changes: 108 additions & 0 deletions vitrivr-engine-module-torchserve/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version "$version_kotlin"
id 'maven-publish'
id 'signing'
id 'com.google.protobuf' version '0.9.4'
}

repositories {
mavenCentral()
}

dependencies {
api project(':vitrivr-engine-core')

/** vitrivr engine Core is required for running tests. */
testImplementation(testFixtures(project(':vitrivr-engine-core')))

/** TwelveMonkeys. */
implementation group: 'com.twelvemonkeys.imageio', name: 'imageio-core', version: version_twelvemonkeys
implementation group: 'com.twelvemonkeys.imageio', name: 'imageio-jpeg', version: version_twelvemonkeys

/** gRPC */
api group: 'com.google.protobuf', name: 'protobuf-java', version: version_protobuf
api group: 'com.google.protobuf', name: 'protobuf-kotlin', version: version_protobuf
api group: 'io.grpc', name: 'grpc-netty', version: version_grpc
api group: 'io.grpc', name: 'grpc-protobuf', version: version_grpc
api group: 'io.grpc', name: 'grpc-stub', version: version_grpc
api group: 'io.grpc', name: 'grpc-auth', version: version_grpc
api group: 'io.grpc', name: 'grpc-kotlin-stub', version: '1.4.1'
api group: 'com.google.auth', name: 'google-auth-library-oauth2-http', version: '1.24.0'
}

protobuf {
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:$version_grpc"
}
grpckt {
artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
}
}
protoc {
artifact = "com.google.protobuf:protoc:$version_protobuf"
}
generateProtoTasks {
all()*.plugins {
grpc {
outputSubDir = 'java'
}
grpckt {
outputSubDir = 'kotlin'
}
kotlin {}
}
}
}

/* Publication of vitrivr engine query to Maven Central. */
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'org.vitrivr'
artifactId = 'vitrivr-engine-module-torchserve'
version = System.getenv().getOrDefault("MAVEN_PUBLICATION_VERSION", version.toString())
from components.java
pom {
name = 'vitrivr Engine TorchServe module'
description = 'A module that adds facilities to call models via torch serve.'
url = 'https://github.com/vitrivr/vitrivr-engine/'
licenses {
license {
name = 'MIT License'
}
}
developers {
developer {
id = 'ppanopticon'
name = 'Ralph Gasser'
email = '[email protected]'
}
developer {
id = 'lucaro'
name = 'Luca Rossetto'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:https://github.com/vitrivr/vitrivr-engine.git'
url = 'https://github.com/vitrivr/vitrivr-engine/'
}
}
}
}
repositories {
repositories {
maven {
def releasesRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
name = "OSSRH"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
}
}
Loading

0 comments on commit a44a864

Please sign in to comment.