weaviate.contextionary
Contextionary module used to interact with Weaviate’s contextionary module.
- class weaviate.contextionary.Contextionary(connection: Connection)
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:
connection (weaviate.connect.Connection) – Connection object to an active and running Weaviate instance.
- extend(concept: str, definition: str, weight: float = 1.0) None
Extend the text2vec-contextionary with new concepts
- Parameters:
concept (str) – The new concept that should be added that is not in the Weaviate or needs to be updated, e.g. an abbreviation.
definition (str) – The definition of the new concept.
weight (float, 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
Retrieves the vector representation of the given concept.
- Parameters:
concept (str) – 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:
A dictionary containing info and the vector/s of the concept. The vector might be empty if the text2vec-contextionary does not contain it.
- Return type:
dict
- Raises:
requests.ConnectionError – If the network connection to weaviate fails.
weaviate.UnexpectedStatusCodeException – If weaviate reports a none OK status.