Skip to content

Python: Int test fixes #12542

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

Merged
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
2 changes: 1 addition & 1 deletion python/samples/concepts/memory/simple_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def main():
) as record_collection:
# Create the collection after wiping it
print_with_color("Creating test collection!", Colors.CGREY)
await record_collection.delete_create_collection()
await record_collection.ensure_collection_exists()

# First add vectors to the records
print_with_color("Adding records!", Colors.CBLUE)
Expand Down
1 change: 1 addition & 0 deletions python/samples/concepts/rag/rag_with_vector_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def main():
kernel.add_service(OpenAIChatCompletion())

async with InMemoryCollection(record_type=BudgetItem) as collection:
await collection.ensure_collection_exists()
# Add information to the collection
await collection.upsert(
[
Expand Down
6 changes: 4 additions & 2 deletions python/samples/getting_started/05-memory-and-embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"id": "77fdfa86",
"metadata": {},
"outputs": [
Expand All @@ -702,7 +702,9 @@
"from semantic_kernel.connectors.azure_ai_search import AzureAISearchCollection\n",
"\n",
"azs_memory = AzureAISearchCollection(record_type=GitHubFile)\n",
"await azs_memory.delete_create_collection()\n",
"# We explicitly delete the collection if it exists to ensure a clean state\n",
"await azs_memory.ensure_collection_deleted()\n",
"await azs_memory.ensure_collection_exists()\n",
"# Add records to the collection\n",
"await azs_memory.upsert(github_files)"
]
Expand Down
12 changes: 6 additions & 6 deletions python/semantic_kernel/connectors/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ def _unpack_results(
for idx, id in enumerate(ids):
record: dict[str, Any] = {"id": id}
# Add vector field if present
if documents is not None and idx < len(documents[0]):
if documents is not None and documents[0] is not None and idx < len(documents[0]):
record["document"] = documents[0][idx]
elif embeddings is not None and idx < len(embeddings[0]):
elif embeddings is not None and embeddings[0] is not None and idx < len(embeddings[0]):
record["embedding"] = embeddings[0][idx]
# Add distance if present
if distances is not None and isinstance(distances, list) and idx < len(distances[0]):
record["distance"] = distances[0][idx]
if distances is not None and distances[0] is not None and idx < len(distances[0]): # type: ignore
record["distance"] = distances[0][idx] # type: ignore
# Add metadata if present
if metadatas is not None and idx < len(metadatas[0]) and metadatas[0] is not None:
if metadatas is not None and metadatas[0] is not None and idx < len(metadatas[0]):
metadata = metadatas[0] if isinstance(metadatas[0], dict) else metadatas[0][idx] # type: ignore
if metadata and isinstance(metadata, dict):
record.update(metadata)
Expand Down Expand Up @@ -350,7 +350,7 @@ async def _inner_search(
results = self._get_collection().query(**args)
records = self._unpack_results(results, options.include_vectors, include_distances=True)
return KernelSearchResults(
results=self._get_vector_search_results_from_results(records), total_count=len(records)
results=self._get_vector_search_results_from_results(records), total_count=len(records) if records else 0
)

@override
Expand Down
4 changes: 2 additions & 2 deletions python/tests/samples/test_concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from samples.concepts.prompt_templates.configuring_prompts import main as configuring_prompts
from samples.concepts.prompt_templates.load_yaml_prompt import main as load_yaml_prompt
from samples.concepts.prompt_templates.template_language import main as template_language
from samples.concepts.rag.rag_with_vector_collection import main as rag_with_text_memory_plugin
from samples.concepts.rag.rag_with_vector_collection import main as rag_with_vector_collection
from samples.concepts.service_selector.custom_service_selector import main as custom_service_selector
from samples.concepts.text_completion.text_completion import main as text_completion
from samples.getting_started_with_agents.chat_completion.step01_chat_completion_agent_simple import (
Expand Down Expand Up @@ -256,7 +256,7 @@
id="simple_memory",
marks=pytest.mark.skipif(os.getenv(MEMORY_CONCEPT_SAMPLE, None) is None, reason="Not running memory samples."),
),
param(rag_with_text_memory_plugin, [], id="rag_with_text_memory_plugin"),
param(rag_with_vector_collection, [], id="rag_with_vector_collection"),
param(
custom_service_selector,
[],
Expand Down