$npx -y skills add saskinosie/weaviate-claude-skills --skill weaviate-query-agentSearch and retrieve data from local Weaviate using semantic search, filters, RAG, and hybrid queries
| 1 | # Weaviate Query Agent Skill |
| 2 | |
| 3 | This skill helps you search and retrieve data from your **local Weaviate collections** using semantic vector search, keyword search, filters, and RAG capabilities. |
| 4 | |
| 5 | ## Important Note |
| 6 | |
| 7 | **This skill is designed for LOCAL Weaviate instances only.** Ensure you have Weaviate running locally in Docker before using this skill. |
| 8 | |
| 9 | ## Purpose |
| 10 | |
| 11 | Query your local Weaviate collections intelligently to find relevant information, perform Q&A, and analyze your data. |
| 12 | |
| 13 | ## When to Use This Skill |
| 14 | |
| 15 | - User wants to search for information in a collection |
| 16 | - User asks questions that need semantic search |
| 17 | - User needs to filter results by specific criteria |
| 18 | - User wants to use RAG (Retrieval Augmented Generation) for Q&A |
| 19 | - User asks about finding similar items |
| 20 | - User needs to combine vector search with filters |
| 21 | |
| 22 | ## Prerequisites Check |
| 23 | |
| 24 | **Claude should verify these prerequisites before proceeding:** |
| 25 | |
| 26 | 1. ✅ **weaviate-local-setup** completed - Python environment and dependencies installed |
| 27 | 2. ✅ **weaviate-connection** completed - Successfully connected to Weaviate |
| 28 | 3. ✅ **weaviate-data-ingestion** used - Collection has data to query |
| 29 | 4. ✅ **Docker container running** - Weaviate is accessible at localhost:8080 |
| 30 | |
| 31 | **If any prerequisites are missing, Claude should:** |
| 32 | - Load the required prerequisite skill first |
| 33 | - Guide the user through the setup |
| 34 | - Then return to this skill |
| 35 | |
| 36 | ## Prerequisites |
| 37 | |
| 38 | - **Local Weaviate running in Docker** (see **weaviate-local-setup** skill) |
| 39 | - Active Weaviate connection (use **weaviate-connection** skill first) |
| 40 | - Collection with data (use **weaviate-data-ingestion** skill to add data) |
| 41 | - Python weaviate-client library installed |
| 42 | |
| 43 | ## Query Types |
| 44 | |
| 45 | ### 1. Semantic Search (Vector Search) |
| 46 | |
| 47 | Find objects semantically similar to your query: |
| 48 | |
| 49 | ```python |
| 50 | import weaviate |
| 51 | |
| 52 | # Assuming client is already connected |
| 53 | collection = client.collections.get("Articles") |
| 54 | |
| 55 | # Search by meaning |
| 56 | response = collection.query.near_text( |
| 57 | query="artificial intelligence and machine learning", |
| 58 | limit=5 |
| 59 | ) |
| 60 | |
| 61 | # Display results |
| 62 | for obj in response.objects: |
| 63 | print(f"Title: {obj.properties['title']}") |
| 64 | print(f"Content: {obj.properties['content'][:200]}...") |
| 65 | print(f"Score: {obj.metadata.score}\n") |
| 66 | ``` |
| 67 | |
| 68 | ### 2. Search with Specific Properties |
| 69 | |
| 70 | Return only the fields you need: |
| 71 | |
| 72 | ```python |
| 73 | response = collection.query.near_text( |
| 74 | query="vector databases", |
| 75 | limit=5, |
| 76 | return_properties=["title", "author", "publishDate"] |
| 77 | ) |
| 78 | |
| 79 | for obj in response.objects: |
| 80 | print(f"{obj.properties['title']} by {obj.properties['author']}") |
| 81 | ``` |
| 82 | |
| 83 | ### 3. Keyword Search (BM25) |
| 84 | |
| 85 | Traditional keyword-based search: |
| 86 | |
| 87 | ```python |
| 88 | from weaviate.classes.query import QueryReference |
| 89 | |
| 90 | response = collection.query.bm25( |
| 91 | query="vector search", |
| 92 | limit=5 |
| 93 | ) |
| 94 | |
| 95 | for obj in response.objects: |
| 96 | print(f"Title: {obj.properties['title']}") |
| 97 | ``` |
| 98 | |
| 99 | ### 4. Hybrid Search (Best of Both Worlds) |
| 100 | |
| 101 | Combine semantic and keyword search: |
| 102 | |
| 103 | ```python |
| 104 | response = collection.query.hybrid( |
| 105 | query="machine learning applications", |
| 106 | limit=5, |
| 107 | alpha=0.5 # 0 = pure BM25, 1 = pure vector, 0.5 = balanced |
| 108 | ) |
| 109 | |
| 110 | for obj in response.objects: |
| 111 | print(f"Title: {obj.properties['title']}") |
| 112 | print(f"Score: {obj.metadata.score}\n") |
| 113 | ``` |
| 114 | |
| 115 | ### 5. Filter Results |
| 116 | |
| 117 | Search with conditions: |
| 118 | |
| 119 | ```python |
| 120 | from weaviate.classes.query import Filter |
| 121 | |
| 122 | # Search with author filter |
| 123 | response = collection.query.near_text( |
| 124 | query="AI advancements", |
| 125 | limit=5, |
| 126 | filters=Filter.by_property("author").equal("Jane Smith") |
| 127 | ) |
| 128 | |
| 129 | # Multiple filters |
| 130 | response = collection.query.near_text( |
| 131 | query="technology trends", |
| 132 | limit=10, |
| 133 | filters=( |
| 134 | Filter.by_property("author").equal("Jane Smith") & |
| 135 | Filter.by_property("publishDate").greater_than("2024-01-01T00:00:00Z") |
| 136 | ) |
| 137 | ) |
| 138 | |
| 139 | # Filter by array contains |
| 140 | response = collection.query.near_text( |
| 141 | query="programming", |
| 142 | filters=Filter.by_property("tags").contains_any(["python", "javascript"]) |
| 143 | ) |
| 144 | ``` |
| 145 | |
| 146 | ### 6. Filter Operators |
| 147 | |
| 148 | ```python |
| 149 | from weaviate.classes.query import Filter |
| 150 | |
| 151 | # Equality |
| 152 | Filter.by_property("status").equal("published") |
| 153 | |
| 154 | # Comparison |
| 155 | Filter.by_property("price").greater_than(100) |
| 156 | Filter.by_property("price").less_than(500) |
| 157 | Filter.by_property("price").greater_or_equal(100) |
| 158 | Filter.by_property("price").less_or_equal(500) |
| 159 | |
| 160 | # String matching |
| 161 | Filter.by_property("title").like("*vector*") # Contains "vector" |
| 162 | |
| 163 | # Array operations |
| 164 | Filter.by_property("tags").contains_any(["ai", "ml"]) |
| 165 | Filter.by_property("tags").contains_all(["python", "tutorial"]) |
| 166 | |
| 167 | # Combine filters |
| 168 | (Filter.by_property("price").greater_than(100) & |
| 169 | Filter.by_property("category").equal("Electronics")) |
| 170 | |
| 171 | # OR conditions |
| 172 | (Filter.by_property("author").equal("John") | |
| 173 | Filter.by_property("author").equal("Jane") |