Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Azure AI Search Vector Store #17651

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,5 @@ Pipfile.lock

# pyright
pyrightconfig.json

poetry.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@


def create_node_from_result(
result: Dict[str, Any], field_mapping: Dict[str, str]
result: Dict[str, Any],
field_mapping: Dict[str, str],
) -> BaseNode:
"""Create a node from a search result.

Expand All @@ -22,28 +23,52 @@ def create_node_from_result(
Returns:
BaseNode: Created node
"""
metadata_str = result[field_mapping["metadata"]]
metadata = json.loads(metadata_str) if metadata_str else {}
node_id = result[field_mapping["id"]]
chunk = result[field_mapping["chunk"]]

# Try LlamaIndex metadata first
metadata = {}
if field_mapping["metadata"] in result:
metadata_str = result[field_mapping["metadata"]]
if metadata_str:
try:
metadata = json.loads(metadata_str)
except json.JSONDecodeError:
logger.debug(
"Could not parse metadata JSON, if chunk is not empty, we'll use it anyways"
)
if len(chunk) == 0:
raise json.JSONDecodeError(
"Could not parse metadata JSON, and chunk is empty"
)

try:
# Try creating node using current metadata format
node = metadata_dict_to_node(metadata)
node.set_content(result[field_mapping["chunk"]])
node.embedding = result.get(field_mapping["embedding"])
node.set_content(chunk)
except Exception:
# NOTE: deprecated legacy logic for backward compatibility
metadata, node_info, relationships = legacy_metadata_dict_to_node(metadata)
try:
metadata, node_info, relationships = legacy_metadata_dict_to_node(metadata)
except Exception:
# If both metadata conversions fail, assume flat metadata structure
node_info = {}
relationships = {}

node = TextNode(
text=result[field_mapping["chunk"]],
id_=result[field_mapping["id"]],
text=chunk,
id_=node_id,
metadata=metadata,
start_char_idx=node_info.get("start", None),
end_char_idx=node_info.get("end", None),
relationships=relationships,
)
if field_mapping.get("embedding"):
node.embedding = result.get(field_mapping["embedding"])

# Add embedding if available
if "embedding" in field_mapping:
node.embedding = result.get(field_mapping["embedding"])

logger.debug(f"Retrieved node id {node_id} with node data of {node}")
return node


Expand Down Expand Up @@ -93,6 +118,8 @@ def create_search_request(
filter_str (Optional[str]): OData filter string
batch_size (int): Size of batch to retrieve
offset (int): Number of results to skip
semantic_config_name (Optional[str]): Name of semantic configuration to use
vector_search_profile (Optional[str]): Name of vector search profile to use

Returns:
Dict[str, Any]: Search request parameters
Expand Down
Loading
Loading