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

Feature/cosmosdb crud #146

Merged
merged 14 commits into from
Jan 6, 2025
Merged

Feature/cosmosdb crud #146

merged 14 commits into from
Jan 6, 2025

Conversation

haruki26
Copy link
Contributor

概要

CosmosDBManagerにCRUDを実装する

変更点

このセクションでは、具体的な変更点や修正箇所を箇条書きでリストアップしてください。

  • ドキュメントをフォーマットする関数を作成
  • similarity_search_with_scoreで返却値のmetadataにidを付与する処理を追加
  • get_source_by_idでクエリを使用する形に変更
  • ベクターストアにドキュメントを追加するメソッドを作成
  • ベクターストアのドキュメントを更新するメソッドを作成

ドキュメントの削除は継承元のdelete_document_by_idで行えることを確認しました。

関連Issue

このセクションでは、このPRが関連するIssueをリンクしてください。以下のように記述します。

@haruki26 haruki26 requested a review from snow7y December 20, 2024 15:26
@github-actions github-actions bot added the enhancement 新しく機能を追加する label Dec 20, 2024
@haruki26
Copy link
Contributor Author

とりあえずですが作成しました。イメージと違うとこあったら教えてください。

Copy link
Member

@snow7y snow7y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以前の自分のコードの部分かもですが、気になった部分をレビューしました
あとazure.coreのloggerがうるさかったのでワーニング以上のlogしか出力されないように変更するコードを別途プッシュするのでプルお願いします

logger.info("documentを更新します")

# metadataのupdated_atを更新
query = "SELECT c.metadata FROM c WHERE c.id = " + f"'{id}'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでf-stringで埋め込んでいるが、_similarity_search_with_scoreメソッドのようにparametersを使用して埋め込んであげたほうがよさそう

query = "SELECT c.metadata FROM c WHERE c.id = @id"
parameters = [{"name": "@id", "value": id}]
item = self._container.query_items(
query=query, parameters=parameters, enable_cross_partition_query=True
).next()

Copy link
Contributor Author

@haruki26 haruki26 Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query_itemメソッドがparameterslist[dict[str, object]]をふっているせいかmypyエラー出ます。
cast関数でlist[dict[str, Any]]にするとエラー吐かないのでキャストしてます。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query_itemメソッドがparameterslist[dict[str, object]]をふっているせいかmypyエラー出ます。 cast関数でlist[dict[str, Any]]にするとエラー吐かないのでキャストしてます。

良いと思います


def _max_level(text: str) -> int:
"""Markdownのヘッダーの最大レベルを返す関数"""
level = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re module使ったらもう少し簡単に書ける

headers = re.findall(r"^#+", text, re.MULTILINE)
return max([len(h) for h in headers]) if headers else 0

@haruki26
Copy link
Contributor Author

ツールの動作確認しました。現在、ベクターサーチの結果からidを取得してidでもう一度クエリした結果を返すようになっているのですが、ベクターサーチの結果をそのまま返すようにしても問題無いでしょうか?

@haruki26
Copy link
Contributor Author

haruki26 commented Jan 6, 2025

langchain側でデフォルトでidを取得するようになっていたのでオーバーライドを削除しました。

@haruki26 haruki26 merged commit b6b3db0 into main Jan 6, 2025
2 checks passed
@haruki26 haruki26 deleted the feature/cosmosdb-crud branch January 6, 2025 14:21
@haruki26 haruki26 restored the feature/cosmosdb-crud branch January 6, 2025 14:21
@haruki26 haruki26 deleted the feature/cosmosdb-crud branch January 6, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 新しく機能を追加する
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants