@@ -80,6 +80,10 @@ class WeaviateConfiguration(BaseModel):
8080 weaviate_rw_api_key : Optional [str ] = None
8181 embeddings_rate_limit : Optional [int ] = 3000
8282 default_batch_size : Optional [int ] = 20
83+ username : Optional [str ] = None
84+ password : Optional [str ] = None
85+ api_key : Optional [str ] = None
86+ additional_headers : Optional [dict ] = {}
8387
8488
8589class Weaviate (VectorStoreInterface ):
@@ -130,8 +134,8 @@ def check_batch_result(results: Optional[List[Dict[str, Any]]]) -> None:
130134 json .dumps (result ['result' ]['errors' ]),
131135 ),
132136 )
133-
134- headers = {}
137+
138+ headers = configuration . additional_headers
135139 if configuration .openai_key is not None :
136140 headers ['X-OpenAI-Api-Key' ] = configuration .openai_key
137141 if configuration .cohere_api_key is not None :
@@ -144,10 +148,25 @@ def check_batch_result(results: Optional[List[Dict[str, Any]]]) -> None:
144148 headers ['authorization' ] = 'Bearer ' + \
145149 configuration .weaviate_rw_api_key
146150
147- self ._client = weaviate .Client (
148- url = configuration .url ,
149- additional_headers = headers ,
150- )
151+ if configuration .username is not None and configuration .password is not None :
152+ self ._client = weaviate .Client (
153+ url = configuration .url ,
154+ auth_client_secret = weaviate .AuthClientPassword (
155+ username = configuration .username , password = configuration .password ),
156+ additional_headers = headers ,
157+ )
158+ elif configuration .api_key is not None :
159+ self ._client = weaviate .Client (
160+ url = configuration .url ,
161+ auth_client_secret = weaviate .AuthApiKey (
162+ api_key = configuration .api_key ),
163+ additional_headers = headers ,
164+ )
165+ else :
166+ self ._client = weaviate .Client (
167+ url = configuration .url ,
168+ additional_headers = headers ,
169+ )
151170
152171 self .client .batch .configure (
153172 batch_size = DEFAULT_BATCH_SIZE ,
@@ -234,6 +253,7 @@ def similarity_search(self, index_name: str, document_query: DocumentQuery, **kw
234253 properties = [document_query .page_content_key ]
235254 for key in document_query .metadata .get ('additional_properties' , []):
236255 properties .append (key )
256+ additional_metadata_properties = document_query .metadata .get ('metadata_properties' , ['id' , 'certainty' , 'distance' ])
237257
238258 if kwargs .get ('search_distance' ):
239259 nearText ['certainty' ] = kwargs .get ('search_distance' )
@@ -254,7 +274,7 @@ def similarity_search(self, index_name: str, document_query: DocumentQuery, **kw
254274 query_obj = query_obj .with_where (whereFilter )
255275 query_response = query_obj .with_near_text (nearText ).with_limit (
256276 document_query .limit ,
257- ).with_additional ([ 'id' , 'certainty' , 'distance' ] ).do ()
277+ ).with_additional (additional_metadata_properties ).do ()
258278 except Exception as e :
259279 logger .error ('Error in similarity search: %s' % e )
260280 raise e
0 commit comments