weaviate.contextionary package

Contextionary module used to interact with Weaviate’s contextionary module.

class weaviate.contextionary.Contextionary(connection: Connection)[source]

Bases: object

Contextionary class used to add extend the Weaviate contextionary module or to get vector/s of a specific concept.

Initialize a Contextionary class instance.

Parameters

connectionweaviate.connect.Connection

Connection object to an active and running Weaviate instance.

extend(concept: str, definition: str, weight: float = 1.0) None[source]

Extend the text2vec-contextionary with new concepts

Parameters

conceptstr

The new concept that should be added that is not in the Weaviate or needs to be updated, e.g. an abbreviation.

definitionstr

The definition of the new concept.

weightfloat, optional

The weight of the new definition compared to the old one, must be in-between the interval [0.0; 1.0], by default 1.0

Examples

>>> client.contextionary.extend(
...     concept = 'palantir',
...     definition = 'spherical stone objects used for communication in Middle-earth'
... )

Raises

TypeError

If an argument is not of an appropriate type.

ValueError

If ‘weight’ is outside the interval [0.0; 1.0].

requests.ConnectionError

If text2vec-contextionary could not be extended.

weaviate.UnexpectedStatusCodeException

If the network connection to weaviate fails.

get_concept_vector(concept: str) dict[source]

Retrieves the vector representation of the given concept.

Parameters

conceptstr

Concept for which the vector should be retrieved. May be camelCase for word combinations.

Examples

>>> client.contextionary.get_concept_vector('king')
{
    "individualWords": [
        {
        "info": {
            "nearestNeighbors": [
            {
                "word": "king"
            },
            {
                "distance": 5.7498446,
                "word": "kings"
            },
            ...,
            {
                "distance": 6.1396513,
                "word": "queen"
            }
            ],
            "vector": [
            -0.68988,
            ...,
            -0.561865
            ]
        },
        "present": true,
        "word": "king"
        }
    ]
}

Returns

dict

A dictionary containing info and the vector/s of the concept. The vector might be empty if the text2vec-contextionary does not contain it.

Raises

requests.ConnectionError

If the network connection to weaviate fails.

weaviate.UnexpectedStatusCodeException

If weaviate reports a none OK status.

Submodules

weaviate.contextionary.crud_contextionary module

Contextionary class definition.

class weaviate.contextionary.crud_contextionary.Contextionary(connection: Connection)[source]

Bases: object

Contextionary class used to add extend the Weaviate contextionary module or to get vector/s of a specific concept.

Initialize a Contextionary class instance.

Parameters

connectionweaviate.connect.Connection

Connection object to an active and running Weaviate instance.

extend(concept: str, definition: str, weight: float = 1.0) None[source]

Extend the text2vec-contextionary with new concepts

Parameters

conceptstr

The new concept that should be added that is not in the Weaviate or needs to be updated, e.g. an abbreviation.

definitionstr

The definition of the new concept.

weightfloat, optional

The weight of the new definition compared to the old one, must be in-between the interval [0.0; 1.0], by default 1.0

Examples

>>> client.contextionary.extend(
...     concept = 'palantir',
...     definition = 'spherical stone objects used for communication in Middle-earth'
... )

Raises

TypeError

If an argument is not of an appropriate type.

ValueError

If ‘weight’ is outside the interval [0.0; 1.0].

requests.ConnectionError

If text2vec-contextionary could not be extended.

weaviate.UnexpectedStatusCodeException

If the network connection to weaviate fails.

get_concept_vector(concept: str) dict[source]

Retrieves the vector representation of the given concept.

Parameters

conceptstr

Concept for which the vector should be retrieved. May be camelCase for word combinations.

Examples

>>> client.contextionary.get_concept_vector('king')
{
    "individualWords": [
        {
        "info": {
            "nearestNeighbors": [
            {
                "word": "king"
            },
            {
                "distance": 5.7498446,
                "word": "kings"
            },
            ...,
            {
                "distance": 6.1396513,
                "word": "queen"
            }
            ],
            "vector": [
            -0.68988,
            ...,
            -0.561865
            ]
        },
        "present": true,
        "word": "king"
        }
    ]
}

Returns

dict

A dictionary containing info and the vector/s of the concept. The vector might be empty if the text2vec-contextionary does not contain it.

Raises

requests.ConnectionError

If the network connection to weaviate fails.

weaviate.UnexpectedStatusCodeException

If weaviate reports a none OK status.