Skip to content

Commit

Permalink
add schemas with embedding tests outside of patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Feb 7, 2025
1 parent 6b2bbc4 commit 58ca89e
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 151 deletions.
6 changes: 3 additions & 3 deletions internal/db/definition_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,12 @@ func validateEmbeddingProviderAndModel(
if embedding.Provider == "" {
return client.ErrEmptyProviderForEmbedding
}
if embedding.Model == "" {
return client.ErrEmptyModelForEmbedding
}
if _, supported := supportedEmbeddingProviders[embedding.Provider]; !supported {
return client.NewErrUnknownEmbeddingProvider(embedding.Provider)
}
if embedding.Model == "" {
return client.ErrEmptyModelForEmbedding
}
}
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestColDescrUpdate_AddVectorEmbeddingWithMissingProvider_ShouldError(t *tes
testUtils.ExecuteTestCase(t, test)
}

func TestColDescrUpdate_AddVectorEmbeddingWithUnsupportedgProvider_ShouldError(t *testing.T) {
func TestColDescrUpdate_AddVectorEmbeddingWithUnsupportedProvider_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.SchemaUpdate{
Expand Down
147 changes: 0 additions & 147 deletions tests/integration/mutation/create/embeddings/embedding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,153 +18,6 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestMutationCreate_WithStringForEmbedding_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name_v: [String!] @embedding
}
`,
ExpectedError: "invalid type for vector embedding",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithIntForEmbedding_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name_v: [Int!] @embedding
}
`,
ExpectedError: "invalid type for vector embedding",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithFloatForEmbedding_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name_v: [Float!] @embedding
}
`,
ExpectedError: "invalid type for vector embedding",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithFloat64ForEmbedding_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name_v: [Float64!] @embedding
}
`,
ExpectedError: "invalid type for vector embedding",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithNillableFloat32ForEmbedding_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name_v: [Float32] @embedding
}
`,
ExpectedError: "invalid type for vector embedding",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithFloat32ForEmbedding_ShouldSucceed(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
name_v: [Float32!] @embedding(fields: ["name"], provider: "ollama", model: "nomic-embed-text", url: "http://localhost:11434/api")
}
`,
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithNonExistantField_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
name_v: [Float32!] @embedding(fields: ["name", "about"])
}
`,
ExpectedError: "the given field does not exist. Embedding generation field: about",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithInvalidEmbeddingGenerationFieldType_ShouldError(t *testing.T) {
test := testUtils.TestCase{
Description: "Create mutation with invalid type for embedding",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
custom: JSON
name_v: [Float32!] @embedding(fields: ["name", "custom"])
}
`,
ExpectedError: "invalid field type for vector embedding generation. Actual: JSON",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestMutationCreate_WithMultipleEmbeddingFields_ShouldSucceed(t *testing.T) {
test := testUtils.TestCase{
Description: "Simple create mutation with multiple embedding fields",
Expand Down
Loading

0 comments on commit 58ca89e

Please sign in to comment.