-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[fix] Implement weaviate knowledge upsert. Improve AgentKnowledge class. #3784
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
kausmeows
merged 21 commits into
agno-agi:main
from
Siete-F:implement-weaviate-knowledge-upsert
Aug 8, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
570755b
initial attempt to implement Weaviate Upsert. But without a full file…
a2534ab
Merge remote-tracking branch 'origin/main' into implement-weaviate-kn…
85c7d12
Some mypy issues. The "document.name" is an Optional, therefore check…
d1e88b8
Added a final condition. This is the best upsert solution with the li…
5a3eef1
typo?
93d2052
Merge branch 'main' into implement-weaviate-knowledge-upsert
Siete-F 493093d
Merge branch 'main' into implement-weaviate-knowledge-upsert
Siete-F 67e923d
Changed upsert error to warning and implemented it everywhere.
32169df
Centralized init code for AgentKnowledge methods. Ran ruff formatter …
a34bfdb
Weaviate upsert example added. ready for merge.
61a52ea
Merge branch 'main' into implement-weaviate-knowledge-upsert
kausmeows ae42642
Changed to info log
ea783ea
Merge branch 'implement-weaviate-knowledge-upsert' of https://github.…
5f359e5
Merge branch 'main' into implement-weaviate-knowledge-upsert
Siete-F c9a922b
Merge branch 'main' into implement-weaviate-knowledge-upsert
Siete-F 8be2758
Missed the potentially un-defined vector_db
Siete-F 1a6efef
It doesn't recognize the check for the missing vector_db in the sub f…
Siete-F d65e1d2
Added await's for async functions.
Siete-F 3f4cea5
Merge branch 'main' into implement-weaviate-knowledge-upsert
Siete-F c25a8ea
Merge branch 'main' into implement-weaviate-knowledge-upsert
Siete-F 110b6b4
Merge branch 'main' into implement-weaviate-knowledge-upsert
kausmeows 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
80 changes: 80 additions & 0 deletions
80
cookbook/agent_concepts/knowledge/vector_dbs/weaviate_db/weaviate_db_upsert.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,80 @@ | ||
| """ | ||
| This example demonstrates using Weaviate as a vector database. | ||
|
|
||
| Installation: | ||
| pip install weaviate-client | ||
|
|
||
| You can use either Weaviate Cloud or a local instance. | ||
|
|
||
| Weaviate Cloud Setup: | ||
| 1. Create account at https://console.weaviate.cloud/ | ||
| 2. Create a cluster and copy the "REST endpoint" and "Admin" API Key. Then set environment variables: | ||
| export WCD_URL="your-cluster-url" | ||
| export WCD_API_KEY="your-api-key" | ||
|
|
||
| Local Development Setup: | ||
| 1. Install Docker from https://docs.docker.com/get-docker/ | ||
| 2. Run Weaviate locally: | ||
| docker run -d \ | ||
| -p 8080:8080 \ | ||
| -p 50051:50051 \ | ||
| --name weaviate \ | ||
| cr.weaviate.io/semitechnologies/weaviate:1.28.4 | ||
| or use the script `cookbook/scripts/run_weviate.sh` to start a local instance. | ||
| 3. Remember to set `local=True` on the Weaviate instantiation. | ||
| """ | ||
|
|
||
| from agno.knowledge.pdf_url import PDFUrlKnowledgeBase | ||
| from agno.knowledge.document import DocumentKnowledgeBase | ||
| from agno.document import Document | ||
| from agno.vectordb.search import SearchType | ||
| from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate | ||
| from agno.utils.log import set_log_level_to_debug | ||
|
|
||
| from agno.embedder.sentence_transformer import SentenceTransformerEmbedder | ||
| embedder = SentenceTransformerEmbedder() | ||
|
|
||
| vector_db = Weaviate( | ||
| collection="recipes", | ||
| search_type=SearchType.hybrid, | ||
| vector_index=VectorIndex.HNSW, | ||
| distance=Distance.COSINE, | ||
| embedder=embedder, | ||
| local=True, # Set to False if using Weaviate Cloud and True if using local instance | ||
| ) | ||
| # Create knowledge base | ||
| knowledge_base = PDFUrlKnowledgeBase( | ||
| urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], | ||
| vector_db=vector_db, | ||
| ) | ||
|
|
||
| vector_db.drop() | ||
| set_log_level_to_debug() | ||
|
|
||
| knowledge_base.load(recreate=False, upsert=True) | ||
|
|
||
| print("Knowledge base loaded with PDF content. Loading the same data again will not recreate it.") | ||
| knowledge_base.load(recreate=False, upsert=True) | ||
|
|
||
| print("First example finished. Now dropping the knowledge base.") | ||
| vector_db.drop() | ||
|
|
||
| doc1 = Document(content="my first content", name="doc1") | ||
| doc1_modified = Document(content="my first content corrected", name="doc1") | ||
| doc2 = Document(content="my second content", name="doc2") | ||
|
|
||
| knowledge_base = DocumentKnowledgeBase( | ||
| documents=[doc1, doc2], | ||
| vector_db=vector_db, | ||
| ) | ||
| knowledge_base_changed = DocumentKnowledgeBase( | ||
| documents=[doc1_modified, doc2], | ||
| vector_db=vector_db, | ||
| ) | ||
|
|
||
| print("\n\nStart second example. Load initial data...") | ||
| knowledge_base.load(recreate=False, upsert=True) | ||
| print("\nNow uploading the changed data...") | ||
| knowledge_base_changed.load(recreate=False, upsert=True) | ||
| print("Example finished. Now dropping the knowledge base.") | ||
| vector_db.drop() |
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
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.