Updates the requirements on [pymilvus](https://github.com/milvus-io/pymilvus) to permit the latest version. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/milvus-io/pymilvus/releases">pymilvus's releases</a>.</em></p> <blockquote> <h2>PyMilvus 2.5.0 Release Notes</h2> <p>New features:</p> <ul> <li>Report cost in the dml and dql request by <a href="https://github.com/SimFG"><code>@SimFG</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2055">milvus-io/pymilvus#2055</a></li> <li>feat: Support major compaction in ManualCompaction by <a href="https://github.com/wayblink"><code>@wayblink</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2015">milvus-io/pymilvus#2015</a></li> <li>Support Milvus Lite by <a href="https://github.com/junjiejiangjjj"><code>@junjiejiangjjj</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2073">milvus-io/pymilvus#2073</a></li> <li>Enable set_properties and describe_database api by <a href="https://github.com/weiliu1031"><code>@weiliu1031</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2082">milvus-io/pymilvus#2082</a></li> <li>Allowing search iterator on sparse float vector field by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2104">milvus-io/pymilvus#2104</a></li> <li>Accept list of single row scipy.sparse object as input for insert/search by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2111">milvus-io/pymilvus#2111</a></li> <li>Support float16/bfloat16/sparse vector for bulkwriter by <a href="https://github.com/yhmo"><code>@yhmo</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2127">milvus-io/pymilvus#2127</a></li> <li>Support group_size parameter for search_group_by by <a href="https://github.com/MrPresent-Han"><code>@MrPresent-Han</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2130">milvus-io/pymilvus#2130</a></li> <li>Upsert support autoid by <a href="https://github.com/smellthemoon"><code>@smellthemoon</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2173">milvus-io/pymilvus#2173</a></li> <li>Expose reduce_stop_for_best to users(<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2181">#2181</a>) by <a href="https://github.com/MrPresent-Han"><code>@MrPresent-Han</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2183">milvus-io/pymilvus#2183</a></li> <li>Bulkinsert supports importing binlog by <a href="https://github.com/yhmo"><code>@yhmo</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2222">milvus-io/pymilvus#2222</a></li> <li>Add page_retain_order param during search with offset by <a href="https://github.com/PwzXxm"><code>@PwzXxm</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2229">milvus-io/pymilvus#2229</a></li> <li>Support load with Field Partial load by <a href="https://github.com/congqixia"><code>@congqixia</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2228">milvus-io/pymilvus#2228</a></li> <li>Support null and default value by <a href="https://github.com/smellthemoon"><code>@smellthemoon</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2234">milvus-io/pymilvus#2234</a></li> <li>Support the mmap_enable param in the field schema by <a href="https://github.com/SimFG"><code>@SimFG</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2238">milvus-io/pymilvus#2238</a></li> <li>Add strict_group_size and rank_group_scorer for hybrid_search(<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2253">#2253</a>) by <a href="https://github.com/MrPresent-Han"><code>@MrPresent-Han</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2254">milvus-io/pymilvus#2254</a></li> <li>Load configuration without altering the environment by <a href="https://github.com/laipz8200"><code>@laipz8200</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2192">milvus-io/pymilvus#2192</a></li> <li>Update proto to get is_sorted field for GetQuerySegmentInfo by <a href="https://github.com/xiaocai2333"><code>@xiaocai2333</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2280">milvus-io/pymilvus#2280</a></li> <li>Support mvcc and break-down-continue for iterator(<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2278">#2278</a>) by <a href="https://github.com/MrPresent-Han"><code>@MrPresent-Han</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2279">milvus-io/pymilvus#2279</a></li> <li>Support new Function feature by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2257">milvus-io/pymilvus#2257</a></li> <li>Supports filling elements through templates for expression by <a href="https://github.com/xiaocai2333"><code>@xiaocai2333</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2317">milvus-io/pymilvus#2317</a></li> <li>Add compact, get_server_version and flush api by <a href="https://github.com/czs007"><code>@czs007</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2326">milvus-io/pymilvus#2326</a></li> </ul> <p>Enhancements</p> <ul> <li>Upgrade the bulkWriter cloud API call from v1 to v2 by <a href="https://github.com/lentitude2tk"><code>@lentitude2tk</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2245">milvus-io/pymilvus#2245</a></li> <li>enhance: tidy dependencies in tests by <a href="https://github.com/XuanYang-cn"><code>@XuanYang-cn</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/1996">milvus-io/pymilvus#1996</a></li> <li>Update sparse+dense hybrid search example by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2005">milvus-io/pymilvus#2005</a></li> <li>Support UDS by <a href="https://github.com/junjiejiangjjj"><code>@junjiejiangjjj</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2023">milvus-io/pymilvus#2023</a></li> <li>enhance: Update hello_hybrid_sparse_dense.py example to include BGE reranker by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2028">milvus-io/pymilvus#2028</a></li> <li>enhance: add resource group declarative api by <a href="https://github.com/chyezh"><code>@chyezh</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2002">milvus-io/pymilvus#2002</a></li> <li>enhance: Make bulk_writer's requirments optional by <a href="https://github.com/XuanYang-cn"><code>@XuanYang-cn</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2086">milvus-io/pymilvus#2086</a></li> <li>Added grpc as a valid protocol for uri by <a href="https://github.com/brunocfnba"><code>@brunocfnba</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2090">milvus-io/pymilvus#2090</a></li> <li>enhance: print search result more elegantly by <a href="https://github.com/longjiquan"><code>@longjiquan</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2123">milvus-io/pymilvus#2123</a></li> <li>enhance: Check PyMilvus on Windows platform by <a href="https://github.com/XuanYang-cn"><code>@XuanYang-cn</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2136">milvus-io/pymilvus#2136</a></li> <li>Export indexed rows for describe_index by <a href="https://github.com/xiaocai2333"><code>@xiaocai2333</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2148">milvus-io/pymilvus#2148</a></li> <li>Add database operations to MilvusClient by <a href="https://github.com/ashkrisk"><code>@ashkrisk</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2152">milvus-io/pymilvus#2152</a></li> <li>enhance: enable setting properties during create database by <a href="https://github.com/weiliu1031"><code>@weiliu1031</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2168">milvus-io/pymilvus#2168</a></li> <li>enhance: hide zero values when printing by <a href="https://github.com/SimFG"><code>@SimFG</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2200">milvus-io/pymilvus#2200</a></li> <li>enhance: use info level for retry message by <a href="https://github.com/XuanYang-cn"><code>@XuanYang-cn</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2212">milvus-io/pymilvus#2212</a></li> <li>enhance: Make load parameter naming normal by <a href="https://github.com/congqixia"><code>@congqixia</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2243">milvus-io/pymilvus#2243</a></li> <li>enhance: add bitmap index example by <a href="https://github.com/zhagnlu"><code>@zhagnlu</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2376">milvus-io/pymilvus#2376</a></li> </ul> <p>Bug fixes</p> <ul> <li>fix: Remove np.view for floatvector by <a href="https://github.com/XuanYang-cn"><code>@XuanYang-cn</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2048">milvus-io/pymilvus#2048</a></li> <li>fix: pass offset parameter for hybrid search to server by <a href="https://github.com/czs007"><code>@czs007</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2051">milvus-io/pymilvus#2051</a></li> <li>Change sparse related errors to ParamError by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2066">milvus-io/pymilvus#2066</a></li> <li>modified example_tls1.py through MilvusClient by <a href="https://github.com/nish112022"><code>@nish112022</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2065">milvus-io/pymilvus#2065</a></li> <li>remove scipy dependency for sparse while still supporting scipy sparse matrix by <a href="https://github.com/zhengbuqian"><code>@zhengbuqian</code></a> in <a href="https://redirect.github.com/milvus-io/pymilvus/pull/2074">milvus-io/pymilvus#2074</a></li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/milvus-io/pymilvus/commit/73d039428f3e5cd9c02505c02ea6dde7484e1802"><code>73d0394</code></a> fix: when insert do not add function output field to dynamic field (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2382">#2382</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/dd629dd47df35057a71a89ca807308b83e178eea"><code>dd629dd</code></a> enhance: Prepare to release 2.5.0 (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2379">#2379</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/15374f63556ae0b5a40a3b09d17fdeb5076eb19a"><code>15374f6</code></a> enhance: Enhance log messages when Connect with server failed (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2377">#2377</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/a086a9d95f9534d0c8a4d3e9303d13860a22fd99"><code>a086a9d</code></a> enhance: format list privilege group result (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2372">#2372</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/b7c6fd27ee1bbf7ba0709ef2bdc1a13ce61f053a"><code>b7c6fd2</code></a> enhance: add bitmap index example (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2376">#2376</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/46f12b21c80efdfc718bc2ef86d867b710a06f1c"><code>46f12b2</code></a> Add default values to Pop to prevent exceptions (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2373">#2373</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/89cf1a9a5285f1923a138032984c38c0334ec8eb"><code>89cf1a9</code></a> fix: cannot pass consistency level for delete (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2350">#2350</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/c10d61a1db61f454e8f14319b39ad8eb2702227d"><code>c10d61a</code></a> fix: RBAC fix privilege group orm (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2366">#2366</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/99bea06ac773fa8ad36cc77f27d339831ff1ba69"><code>99bea06</code></a> Correct grammar (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2365">#2365</a>)</li> <li><a href="https://github.com/milvus-io/pymilvus/commit/4b4924686f36f36aafdb29ab694e42ce0c798eea"><code>4b49246</code></a> enhance: RBAC grant v2 api (<a href="https://redirect.github.com/milvus-io/pymilvus/issues/2361">#2361</a>)</li> <li>Additional commits viewable in <a href="https://github.com/milvus-io/pymilvus/compare/v2.3.0...v2.5.0">compare view</a></li> </ul> </details> <br /> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Get Started with Semantic Kernel ⚡
Install the latest package:
python -m pip install --upgrade semantic-kernel
If you want to use some of the optional dependencies (OpenAI is installed by default), you can install them with:
python -m pip install --upgrade semantic-kernel[hugging_face]
or all of them:
python -m pip install --upgrade semantic-kernel[all]
AI Services
OpenAI / Azure OpenAI API keys
Make sure you have an OpenAI API Key or Azure OpenAI service key
There are two methods to manage keys, secrets, and endpoints:
-
Store them in environment variables. SK Python leverages pydantic settings to load keys, secrets, and endpoints. This means that there is a first attempt to load them from environment variables. The
.envfile naming applies to how the names should be stored as environment variables. -
If you'd like to use the
.envfile, you will need to configure the.envfile with the following keys in the file (see the.env.examplefile):
OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=""
AZURE_OPENAI_TEXT_DEPLOYMENT_NAME=""
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""
You will then configure the Text/ChatCompletion class with the keyword argument env_file_path:
chat_completion = OpenAIChatCompletion(service_id="test", env_file_path=<path_to_file>)
This optional env_file_path parameter will allow pydantic settings to use the .env file as a fallback to read the settings.
Running a prompt
import asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion
from semantic_kernel.prompt_template import PromptTemplateConfig
kernel = Kernel()
# Prepare OpenAI service using credentials stored in the `.env` file
service_id="chat-gpt"
kernel.add_service(
OpenAIChatCompletion(
service_id=service_id,
)
)
# Alternative using Azure:
# kernel.add_service(
# AzureChatCompletion(
# service_id=service_id,
# )
# )
# Define the request settings
req_settings = kernel.get_prompt_execution_settings_from_service_id(service_id)
req_settings.max_tokens = 2000
req_settings.temperature = 0.7
req_settings.top_p = 0.8
prompt = """
1) A robot may not injure a human being or, through inaction,
allow a human being to come to harm.
2) A robot must obey orders given it by human beings except where
such orders would conflict with the First Law.
3) A robot must protect its own existence as long as such protection
does not conflict with the First or Second Law.
Give me the TLDR in exactly 5 words."""
prompt_template_config = PromptTemplateConfig(
template=prompt,
name="tldr",
template_format="semantic-kernel",
execution_settings=req_settings,
)
function = kernel.add_function(
function_name="tldr_function",
plugin_name="tldr_plugin",
prompt_template_config=prompt_template_config,
)
# Run your prompt
# Note: functions are run asynchronously
async def main():
result = await kernel.invoke(function)
print(result) # => Robots must not harm humans.
if __name__ == "__main__":
asyncio.run(main())
# If running from a jupyter-notebook:
# await main()
Semantic Prompt Functions are Prompts with input parameters
# Create a reusable function summarize function
summarize = kernel.add_function(
function_name="tldr_function",
plugin_name="tldr_plugin",
prompt="{{$input}}\n\nOne line TLDR with the fewest words.",
prompt_template_settings=req_settings,
)
# Summarize the laws of thermodynamics
print(await kernel.invoke(summarize, input="""
1st Law of Thermodynamics - Energy cannot be created or destroyed.
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy."""))
# Summarize the laws of motion
print(await kernel.invoke(summarize, input="""
1. An object at rest remains at rest, and an object in motion remains in motion at constant speed and in a straight line unless acted on by an unbalanced force.
2. The acceleration of an object depends on the mass of the object and the amount of force applied.
3. Whenever one object exerts a force on another object, the second object exerts an equal and opposite on the first."""))
# Summarize the law of universal gravitation
print(await kernel.invoke(summarize, input="""
Every point mass attracts every single other point mass by a force acting along the line intersecting both points.
The force is proportional to the product of the two masses and inversely proportional to the square of the distance between them."""))
# Output:
# > Energy conserved, entropy increases, zero entropy at 0K.
# > Objects move in response to forces.
# > Gravitational force between two point masses is inversely proportional to the square of the distance between them.
Semantic Kernel Notebooks
The repository contains a few Python and C# notebooks that demonstrates how to get started with the Semantic Kernel.
Python notebooks:
- Getting started with Semantic Kernel
- Loading and configuring Semantic Kernel
- Running AI prompts from file
- Creating Prompt Functions at runtime (i.e. inline functions)
- Using Context Variables to Build a Chat Experience
- Introduction to planners
- Building Memory with Embeddings
- Using Hugging Face for Plugins
- Combining native functions and semantic functions
- Groundedness Checking with Semantic Kernel
- Returning multiple results per prompt
- Streaming completions with Semantic Kernel
SK Frequently Asked Questions
How does Python SK compare to the C# version of Semantic Kernel?
The two SDKs are compatible and at the core they follow the same design principles. Some features are still available only in the C# version, and being ported Refer to the FEATURE MATRIX doc to see where things stand in matching the features and functionality of the main SK branch. Over time there will be some features available only in the Python version, and others only in the C# version, for example adapters to external services, scientific libraries, etc.