-
Notifications
You must be signed in to change notification settings - Fork 4k
Python: Feature python vector stores preb #12271
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
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0a92459
Python: Vector store updates core azs (#12114)
eavanvalkenburg 32ab4c4
Python: Update Cosmos and MongoDB (#12115)
eavanvalkenburg 11c8b2d
Python: Update Chroma, Pinecone, Postgres (#12116)
eavanvalkenburg 863ee0f
Python: Update InMemory and Faiss (#12117)
eavanvalkenburg e764e4c
Python: Update Qdrant, Redis, Weaviate (#12119)
eavanvalkenburg 5ae00df
Python: Update SQL (#12120)
eavanvalkenburg 659e9b2
Python: Move old and deprecate (#12121)
eavanvalkenburg 48494a3
Python: Text search updates (#12122)
eavanvalkenburg 9a883be
Python: samples and misc (#12123)
eavanvalkenburg b1cc4d5
Python: Naming updates (#12233)
eavanvalkenburg 5a5f8de
Python: moved vector field to new setup (#12256)
eavanvalkenburg 5581c01
Python: Naming updates (#12233)
eavanvalkenburg 5808235
Python: vector store simplificatons and some cleanup (#12274)
eavanvalkenburg 92e844f
Python: Move connectors (#12282)
eavanvalkenburg c994c27
Python: Int test fix (#12298)
eavanvalkenburg d96756b
Python: Naming and updates (#12462)
eavanvalkenburg e0de230
Python: fixes from feedback for vector store feature branch (#12520)
eavanvalkenburg bd73f5f
Python: upgraded pinecone and redis (#12536)
eavanvalkenburg 679eb6e
Python: Int test fixes (#12542)
eavanvalkenburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...n/samples/concepts/memory/azure_ai_search_hotel_samples/1_interact_with_the_collection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
import asyncio | ||
|
||
from samples.concepts.memory.azure_ai_search_hotel_samples.data_model import ( | ||
HotelSampleClass, | ||
custom_index, | ||
load_records, | ||
) | ||
from semantic_kernel.connectors.ai.open_ai import OpenAITextEmbedding | ||
from semantic_kernel.connectors.azure_ai_search import AzureAISearchCollection | ||
|
||
""" | ||
With the data model and records defined in step_0_data_model.py, this script will create an Azure AI Search collection, | ||
eavanvalkenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
upsert the records, and then search the collection using vector and hybrid search. | ||
The script will print the first five records in the collection and the search results. | ||
The script will also delete the collection at the end. | ||
|
||
Note that we add the OpenAITextEmbedding to the collection, which is used to generate the vectors. | ||
To use the built-in embedding in Azure AI Search, remove this and add that definition to the custom_index. | ||
""" | ||
|
||
|
||
async def main(query: str): | ||
records = load_records() | ||
# Create the Azure AI Search collection | ||
async with AzureAISearchCollection[str, HotelSampleClass]( | ||
record_type=HotelSampleClass, embedding_generator=OpenAITextEmbedding() | ||
) as collection: | ||
# Check if the collection exists. | ||
await collection.ensure_collection_exists(index=custom_index) | ||
await collection.upsert(records) | ||
# get the first five records to check the upsert worked. | ||
results = await collection.get(order_by="HotelName", top=5) | ||
print("Get first five records: ") | ||
if results: | ||
for result in results: | ||
print( | ||
f" {result.HotelId} (in {result.Address.City}, {result.Address.Country}): {result.Description}" | ||
) | ||
|
||
print("\n") | ||
print("Search results using vector: ") | ||
# Use search to search using the vector. | ||
results = await collection.search( | ||
query, | ||
vector_property_name="DescriptionVector", | ||
) | ||
async for result in results.results: | ||
print( | ||
f" {result.record.HotelId} (in {result.record.Address.City}, " | ||
f"{result.record.Address.Country}): {result.record.Description} (score: {result.score})" | ||
) | ||
print("\n") | ||
print("Search results using hybrid: ") | ||
# Use hybrid search to search using the vector. | ||
results = await collection.hybrid_search( | ||
query, | ||
vector_property_name="DescriptionVector", | ||
additional_property_name="Description", | ||
) | ||
async for result in results.results: | ||
print( | ||
f" {result.record.HotelId} (in {result.record.Address.City}, " | ||
f"{result.record.Address.Country}): {result.record.Description} (score: {result.score})" | ||
) | ||
|
||
await collection.ensure_collection_deleted() | ||
|
||
|
||
if __name__ == "__main__": | ||
query = "swimming pool and good internet connection" | ||
asyncio.run(main(query=query)) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.