Coder Social home page Coder Social logo

Struct inconsistencie about pyvespa HOT 4 CLOSED

marcoaleixo avatar marcoaleixo commented on September 25, 2024
Struct inconsistencie

from pyvespa.

Comments (4)

tmaregge avatar tmaregge commented on September 25, 2024 1

Here is a way to reproduce your original schema using Pyvespa:

the_struct = Struct(name="answer", fields=[
      Field(name="folder_ids", type="array<string>"),
      Field(name="likes", type="int"),
      Field(name="dislikes", type="int"),
      Field(name="retriever_name", type="string"),
      Field(name="reader_name", type="string"),
      Field(name="passage_id", type="string"),
      Field(name="user_ids_likes", type="array<string>"),
      Field(name="user_ids_dislikes", type="array<string>"),
])
the_field = Field(name="answers", type="array<answer>", indexing=["summary", "index"])

schema = Schema(name="schema", document=Document())
schema.add_fields(the_field)
schema.document.add_structs(the_struct)

print(schema.schema_to_text)

This produces the following

schema schema {
    document schema {
        field answers type array<answer> {
            indexing: summary | index
        }
        struct answer {
            field folder_ids type array<string> {
            }
            field likes type int {
            }
            field dislikes type int {
            }
            field retriever_name type string {
            }
            field reader_name type string {
            }
            field passage_id type string {
            }
            field user_ids_likes type array<string> {
            }
            field user_ids_dislikes type array<string> {
            }
        }
    }
}

StructField actually belongs to a normal Field, not a Struct. Here is an example:

the_struct = Struct(name="answer", fields=[
      Field(name="foo", type="int"),
])
the_field = Field(name="answers",
                type="array<answer>", 
                indexing=["summary", "index"], 
                struct_fields=[StructField(name="foo", indexing=["attribute"], attribute=["fast-search"])]
)

schema = Schema(name="schema", document=Document())
schema.add_fields(the_field)
schema.document.add_structs(the_struct)

print(schema.schema_to_text)

Output:

schema schema {
    document schema {
        field answers type array<answer> {
            indexing: summary | index
            struct-field foo {
                indexing: attribute
                attribute {
                    fast-search
                }
            }
        }
        struct answer {
            field foo type int {
            }
        }
    }
}

Hope this helps. Reach out if anything is unclear.

from pyvespa.

tmaregge avatar tmaregge commented on September 25, 2024

How are you adding the Struct and Field to the Schema? Could you provide a minimal code example to reproduce the error?

from pyvespa.

marcoaleixo avatar marcoaleixo commented on September 25, 2024

Hey @tmaregge

Already shared above, but basically like this:

Struct(name="answer", fields=[
      StructField(name="folder_ids", type="array<string>", indexing=["summary", "index"]),
      StructField(name="likes", type="int", indexing=["summary", "index"]),
      StructField(name="dislikes", type="int", indexing=["summary", "index"]),
      StructField(name="retriever_name", type="string", indexing=["summary", "index"]),
      StructField(name="reader_name", type="string", indexing=["summary", "index"]),
      StructField(name="passage_id", type="string", indexing=["summary", "index"]),
      StructField(name="user_ids_likes", type="array<string>", indexing=["summary", "index"]),
      StructField(name="user_ids_dislikes", type="array<string>", indexing=["summary", "index"]),
                    ]),
Field(name="answers", type="array<answer>", indexing=["summary", "index"]),

from pyvespa.

marcoaleixo avatar marcoaleixo commented on September 25, 2024

Thank you @tmaregge. I was able to fully reproduce my schema using pyvespa.
Closing this.

from pyvespa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.