Exemple #1
0
def _create_client_from_config(config: dict) -> weaviate.Client:
    """
    Create weaviate client from a config.

    Parameters
    ----------
    config : dict
        The configuration as a dict.

    Returns
    -------
    weaviate.Client
        The configured weaviate client.
    """

    if config["auth"] is None:
        return weaviate.Client(config["url"])
    if config["auth"]["type"] == cfg_vals.config_value_auth_type_client_secret:
        cred = weaviate.AuthClientCredentials(config["auth"]["secret"])
        return weaviate.Client(config["url"], cred)
    if config["auth"]["type"] == cfg_vals.config_value_auth_type_username_pass:
        cred = weaviate.AuthClientPassword(config["auth"]["user"],
                                           config["auth"]["pass"])
        return weaviate.Client(config["url"], cred)

    print("Fatal error unknown authentication type in config!")
    sys.exit(1)
Exemple #2
0
    def test_import_data_from_file(self):
        current_path = '/'.join(__file__.split('/')[:-1])
        client = weaviate.Client("http://localhost:8080")
        client.schema.delete_all()
        client.schema.create(current_path + "/schema.json")

        importer = DataFileImporter(client, current_path + "/data.json", True)
        self.assertIsNone(importer.load())
Exemple #3
0
    def __init__(self):
        url = os.getenv("WEAVIATE_URL")
        if url == "":
            print("env WEAVIATE_URL not set!")
            exit(1)

        self.client = weaviate.Client(url)

        if not self.client.contains_schema():
            self.client.create_schema("schema.json")

        self.things_batch = weaviate.batch.ThingsBatchRequest()
        self.reference_batch = weaviate.batch.ReferenceBatchRequest()
Exemple #4
0
def weaviate_fixture():
    # test if a Weaviate server is already running. If not, start Weaviate docker container locally.
    # Make sure you have given > 6GB memory to docker engine
    try:
        weaviate_server = weaviate.Client(url='http://localhost:8080',
                                          timeout_config=(5, 15))
        weaviate_server.is_ready()
    except:
        print("Starting Weaviate servers ...")
        status = subprocess.run(['docker rm haystack_test_weaviate'],
                                shell=True)
        status = subprocess.run([
            'docker run -d --name haystack_test_weaviate -p 8080:8080 semitechnologies/weaviate:1.4.0'
        ],
                                shell=True)
        if status.returncode:
            raise Exception(
                "Failed to launch Weaviate. Please check docker container logs."
            )
        time.sleep(60)
 def setUp(self) -> None:
     create_schema(schema='project/schema.json', overwrite=True)
     self.client = weaviate.Client("http://localhost:8080")
    prop = {
        "dataType": ["string"],
        "description": "how hot is the BBQ in C",
        "name": "heat",
    }
    client.schema.property.create("Barbecue", prop)
    classes = client.schema.get()['classes']
    found = False
    for class_ in classes:
        if class_["class"] == "Barbecue":
            found = len(class_['properties']) == 1
    if not found:
        raise TestFailedException("Class property not added properly")


if __name__ == "__main__":
    print("Weaviate should be running at local host 8080")
    client = weaviate.Client("http://localhost:8080")
    creating_schema(client)
    integration = IntegrationTestCrud(client)
    integration.test_crud()
    query_data(client)

    gql_integration = TestGraphQL(client)
    gql_integration.get_data()
    gql_integration.aggregate_data()

    contextual(client)

    print("Integration test finished successfully")
Exemple #7
0
#!/usr/bin/env python3.7
import weaviate, csv

client = weaviate.Client("http://weaviate.com:8080")
client.create_schema("./schema.json")

# Set the individual data
rowCounter = 0
for row in csv.reader(open("data.csv", "rU"), delimiter=','):
    if rowCounter == 0:
        rowCounter += 1
        continue
    elif len(row) == 7 and row[6] != '':
        print("ADD: ", row[5])
        client.create_thing(
            {
                "year": int(row[0]),
                "volume": int(row[1]),
                "issue": int(row[2]),
                "doi": str(row[3]),
                "journal": str(row[4]),
                "title": str(row[5]),
                "abstract": str(row[6])
            }, "Article")
 def setUp(self) -> None:
     create_game_schema()
     self.client = weaviate.Client("http://localhost:8080")
     self.manager = helper.Manager(self.client)
     self.uuid_list = []
 def setUp(self) -> None:
     weaviate_url = "http://localhost:8080"
     self.client = weaviate.Client(weaviate_url)
     create_schema.create_schema(schema='project/schema.json',
                                 weaviate_url=weaviate_url,
                                 overwrite=True)
                    if subtitle is not None:
                        inserted_subtitle_uuids.append(subtitle["uuid"])

                time.sleep(2)

                # cross reference
                manager.add_reference_of_game_subtitle(
                    game["uuid"], inserted_subtitle_uuids)
                manager.add_reference_has_subs(video["uuid"],
                                               inserted_subtitle_uuids)

                os.remove(subtitle_path)
            else:
                print("no subtitle is found for this video")
            print()


# def populate_article():
#     with open("data/article_links") as i:
#         for link in i:
#             result = helper.scrap_article(link.strip())
#             print(result)
#             # todo: insert into graph

if __name__ == "__main__":
    create_schema.create_game_schema()
    manager = helper.Manager(weaviate.Client("http://localhost:8080"))
    populate_game(manager)
    populate_video(manager)
    # populate_article()
Exemple #11
0
#!/usr/bin/env python3
import uuid, os, json, sys, time, weaviate, csv
from datetime import datetime
from modules.Weaviate import Weaviate
from utils.helper import *
import csv

DATADIR = sys.argv[2]
WEAVIATE = Weaviate(sys.argv[1])
# CACHEDIR = sys.argv[2]
CLIENT = weaviate.Client(sys.argv[1])


journals = [];
##
# Function to clean up data
##
def processInput(k, v):
    if k == 'Author':
        v = v.replace(' Wsj.Com', '')
        v = v.replace('.', ' ')
        return v
    elif k == 'Summary':
        v = v.replace('\n', ' ')
        return v

    return v

##
# Import the publications without refs except for cities
## 
Exemple #12
0
# from https://github.com/semi-technologies/weaviate-python-client/blob/6a49fae4af7ac097b15e0aaa8641abe0c287f554/ci/integration_test.py

import os
import time
import weaviate
from queries import *

ORIGIN = os.getenv("WEAVIATE_ORIGIN")
if ORIGIN is None:
    ORIGIN = "http://localhost:8080"
w = weaviate.Client(ORIGIN)

print("Checking if weaviate is reachable")
if not w.is_reachable():
    print("Weaviate not reachable")
    exit(2)

if w.contains_schema():
    print("No schema should be present")
    exit(3)

print("Load a schema")
schema_json_file = os.path.join(os.path.dirname(__file__),
                                "people_schema.json")
w.create_schema(schema_json_file)

if not w.contains_schema():
    print("Weaviate does not contain loaded schema")
    exit(4)

print("Create a batch with data")
Exemple #13
0
doc_schema = {
    'classes': [{
        'class':
        'JinaDocv',
        'properties': [
            {
                'dataType': ['blob'],
                'name': '_serialized'
            },
        ],
    }]
}

import weaviate

client = weaviate.Client('http://localhost:8080')

class_exists = False
for c in client.schema.get()['classes']:
    if 'JinaDocv' in c['class']:
        print('\nJinaDocv found\n')
        pprint(c)
        class_exists = True

if class_exists == False:
    print('\nCreating schema with client.schema.create(doc_schema)\n')
    client.schema.create(doc_schema)

d = Document(embedding=[1, 2, 3])
did = client.data_object.create({'_serialized': d.to_base64()},
                                class_name='JinaDocv',
Exemple #14
0
 def setUp(self) -> None:
     create_game_schema()
     self.client = weaviate.Client("http://localhost:8080")
 def getClient(self):
     self.client = weaviate.Client("http://%s:%d" % (self.host, self.port))
     return self.client