Hi @Smit Tiwary ,
I was able to successfully execute the VectorizedQuery. For the purpose of debugging the code, I had programatically generated the embeddings by setting the dimensionality to 1536 i.e. same as the dimensionality of the vector I created in the Azure portal. Please find below:
import random
# Set the dimensionality
dimensionality = 1536
# Generate a random query vector with values between -1 and 1
query_vector = [random.uniform(-1, 1) for _ in range(dimensionality)]
# Print or use the query vector as needed
print(query_vector)
Then I used this query_vector further in the piece of code that you were facing issue with and it is working fine for me now. Please find below:
import json
from azure.search.documents import SearchClient
from azure.search.documents.models import VectorizedQuery
from azure.core.credentials import AzureKeyCredential
# Set the values of these variables to your Azure Cognitive Search service, index, and credentials
search_service_endpoint = "****"
index_name = "langchain-vector-demo"
api_key = "****"
# Create an AzureKeyCredential object with the specified API key
credential = AzureKeyCredential(api_key)
# Create a SearchClient object with the specified endpoint, index name, and credentials
search_client = SearchClient(search_service_endpoint, index_name, credential)
# Create a VectorizedQuery object with the specified query vector and field name
vector_query = VectorizedQuery(vector=query_vector, fields="content_vector", exhaustive=True)
# Perform the vector search and retrieve the search results
results = search_client.search(
search_text=None,
vector_queries=[vector_query],
select=["*"],
)
# Display search results
for result in results:
print(result)
I found that the code is working as expected.
Below are the dimensions of the vector I created in the portal, just for testing, without depending on the GIT embeddings:
Note : Try to add more PRINT / debug statements for knowing the dimensionality, SELECT query columns etc need to match exactly in however way defined in the Azure portal.
- Match the dimensionality Azure Portal Vs Python code.
- Match column names Azure Portal Vs Python code.
Repro Output:
Hope this helps.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful.