I want to create the indexing functionality as an Azure Function to be able to schedule it via cron trigger or execute it ondemand via http triggers.
However after installing the client, even import pinecone breaks the environment.
I am not sure if this is related to pinecone or azure core functions runtime
I have reported this also in Azure Github repo for core tools
opened 08:57AM - 03 Jul 23 UTC
Needs: Triage
My code is just a hello world, I want to use pinecone client to create indexex, … etc.
However by only importing pinecone I get this error:
```
[2023-07-03T08:54:27.276Z] Worker failed to load function: 'createPineConeIndex' with functionId: 'de03aa8b-f597-4ee3-a816-eb54685435b5'.
[2023-07-03T08:54:28.114Z] Result: Failure
Exception: ValueError: Enum RpcLogCategory has no value defined for name 'System'
Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 394, in _handle__function_load_request
logger.info('Successfully processed FunctionLoadRequest, '
File "C:\Users\xx\anaconda3\lib\logging\__init__.py", line 1477, in info
self._log(INFO, msg, args, **kwargs)
File "C:\Users\x\anaconda3\lib\logging\__init__.py", line 1624, in _log
self.handle(record)
File "C:\Users\xx\anaconda3\lib\logging\__init__.py", line 1634, in handle
self.callHandlers(record)
File "C:\Users\xx\anaconda3\lib\logging\__init__.py", line 1696, in callHandlers
hdlr.handle(record)
File "C:\Users\xx\anaconda3\lib\logging\__init__.py", line 968, in handle
self.emit(record)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 821, in emit
Dispatcher.current.on_logging(record, msg)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 206, in on_logging
log_category = protos.RpcLog.RpcLogCategory.Value('System')
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\google\protobuf\internal\enum_type_wrapper.py", line 73, in Value
raise ValueError('Enum {} has no value defined for name {!r}'.format(
```
My code is:
```
import logging
import azure.functions as func
import os
import pinecone
def main(req: func.HttpRequest) -> func.HttpResponse:
#logging.info('Python HTTP trigger function processed a request.')
#pinecone.init(
# api_key=os.getenv("pineconeapikey"), # find at app.pinecone.io
# environment=os.getenv("pineconenvironment"), # next to api key in console
#)
return func.HttpResponse(f"Hello world")
# indexName = req.params.get('indexName')
# if not indexName:
# try:
# req_body = req.get_json()
# except ValueError:
# pass
# else:
# indexName = req_body.get('indexName')
# if indexName:
# if indexName not in pinecone.list_indexes():
# # we create a new index
# pinecone.create_index(
# name=indexName,
# metric='dotproduct',
# dimension=1536 # 1536 dim of text-embedding-ada-002
# )
# return func.HttpResponse(f"Index: {indexName} created. This HTTP triggered function executed successfully.",status_code=200)
# else:
# return func.HttpResponse(f"Index: {indexName} already exists. This HTTP triggered function executed successfully.",status_code=200)
# else:
# return func.HttpResponse(f"Please pass a indexName on the query string or in the request body")
```
as you can see most is commented, when I comment pinecone import, the code works, when I uncomment it, I get all these errors
dra
July 4, 2023, 3:34am
2
@levalencia
Hello!
I tested it with a minimal configuration, and it worked fine with both the Python Programming Model V2 and V1.
Here are the details of the environment I tested on:
Azure Functions Core Tools
Core Tools Version: 4.0.5198 Commit hash: N/A (64-bit)
Function Runtime Version: 4.21.1.20667
Python version 3.10.11 (py)
requirements.txt:
azure-functions
pinecone-client
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
function_app.py:
import azure.functions as func
import pinecone
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.route(route="HttpTrigger")
def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse:
pinecone.init(
api_key="xxxxxx",
environment="xxxxxx"
)
indexName = req.params.get('indexName')
if indexName:
if indexName not in pinecone.list_indexes():
# we create a new index
pinecone.create_index(
name=indexName,
metric='dotproduct',
dimension=1536 # 1536 dim of text-embedding-ada-002
)
return func.HttpResponse(f"Index: {indexName} created. This HTTP triggered function executed successfully.",status_code=200)
else:
return func.HttpResponse(f"Index: {indexName} already exists. This HTTP triggered function executed successfully.",status_code=200)
else:
return func.HttpResponse(f"Please pass a indexName on the query string or in the request body")
It seems you have several packages in use. To identify the issue, you could try adding the packages incrementally to see if any particular package is causing the problem.
Are you using conda or venv?
dra
July 4, 2023, 5:56am
4
@levalencia
Yes, I am using venv. (venv was automatically generated by the tool.)
The environment I tested can be set up using the Azure Functions auto-generation feature in VS Code.
All I did was click a button and made a few modifications to the generated code.
thanks I started from scratch and it works, I think the issue was related to Conda or when selecting the Python interpreter
1 Like