Package: trieve_client_py
trieve_client_pyA client library for accessing trieve.aiInstallationpip install trieve_client_pyUsageFirst, create a client:fromtrieve_clientimportClientclient=Client(base_url="https://api.example.com")If the endpoints you're going to hit require authentication, useAuthenticatedClientinstead:fromtrieve_clientimportAuthenticatedClientapi_key=os.getenv("API_KEY")dataset_id=os.getenv("DATASET_ID")organization_id=os.getenv("ORGANIZATION_ID")client=AuthenticatedClient(base_url="https://api.trieve.ai",prefix="",token=api_key).with_headers({"TR-Dataset":dataset_id,"TR-Organization":organization_id,});Uploading Chunksfromtrieve_client.api.chunkimportcreate_chunkfromtrieve_client.modelsimportCreateChunkData,ReturnCreatedChunkfromtrieve_client.models.error_response_bodyimportErrorResponseBodychunk=CreateChunkData(# We accept html inputs, the html tags are NOT embedded.# HTML does help for us to highlight results in the response.chunk_html=f"<h1>Hello, World! chunk{id}</h1>",# If you have a link that relates to your chunklink=f"https://{id}.com",# Add as many tags as neededtag_set=["example","test",id],# Since we queue writes, tracking id helps to prevent duplicates# This can be any internal id system that you have or simply left# blanktracking_id=id,# You can put a timestamp as when it was made, this helps with the# timerange filter that we havetime_stamp="2021-01-01T00:00:00Z",# You can place a list of group ids that the chunk will automatically# be added to. Chunks can also be added to groups after.group_ids=[],# Similar thing with GroupID just less flexible, adding this chunk to a fileIDfile_id=None,# Chunk Vector is an alternative to chunk_html.# Chunk Vector may be used if you already embedded the datachunk_vector=None,weight=None,# We allow for arbitrary metadatametadata={"anykey":"any-data","id":id,},)chunk_response=create_chunk.sync(tr_dataset=dataset_id,client=client,body=chunk)iftype(chunk_response)==ReturnCreatedChunk:print(f"queue'd pos:{chunk_response.pos_in_queue}")eliftype(chunk_response)==ErrorResponseBody:print(f"Failed{chunk_response.message}")exit(1)Searching Chunks# Conduct an example searchsearch_data=SearchChunkData(# The query that you want to search forquery="example",# The type of search that you want to conductsearch_type="semantic",# Bias search results that are more recentdate_bias=False,# Filters are based on metadata keys that you insertedfilters={"anykey":"any-data",},# Rather or not to fetch collisions, this is a# more advanced feature that is not used oftenget_collisions=False,# We highlight relevant parts of the search highlight_results# the delimeters are what characters to split on. By default# we split on sentence end. (., !, ?)highlight_delimiters=None,# Rather or not to highlight resultshighlight_results=True,# Require that the search results have a links that fuzzy matchlink=["example"],# What page of results to fetchpage=1,# Only fetch results that are in a specified tag grouptag_set=["test"],# A tuple of two strings, the start and end of the time rangetime_range=None,)search_response=search_chunk.sync(tr_dataset=dataset_id,client=client,body=search_data)iftype(search_response)==SearchChunkQueryResponseBody:print(f"Got{search_response.total_chunk_pages}pages of results. Search results:{search_response}")eliftype(search_response)==ErrorResponseBody:print(f"Failed to search body{search_response.message}")exit(1)MoreFor more examples checkout theexamples/directory for a full scriptsRegenerating the apitypesModify the .code-gen/openapi.json to a new version
run.code-gen/generate.shEverything should be up-to-date then