Weaviate GraphQL 질의
강력한 GraphQL API를 사용하여 의미 검색과 데이터 검색을 수행하도록 Weaviate 데이터를 질의하는 방법을 익힙니다.
Weaviate GraphQL 질의은(는) CoddyKit의 무료 Vector Databases: Pinecone, Weaviate & pgvector 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Vector Databases: Pinecone, Weaviate & pgvector 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Vector Databases: Pinecone, Weaviate & pgvector 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Weaviate's GraphQL Power
Welcome! In this lesson, you'll master querying your Weaviate data. Weaviate uses GraphQL, a powerful query language, for flexible and efficient data retrieval.
GraphQL allows you to request exactly the data you need, nothing more, nothing less. This is especially useful for complex searches, including vector similarity.
Basic Data Retrieval: Get
The foundation of querying in Weaviate is the Get operation. It allows you to fetch data objects from a specific class defined in your schema.
- Specify the class name (e.g.,
Article). - Select the properties you want to retrieve (e.g.,
title,content). - Weaviate will return all objects of that class with the specified properties.
Get All Objects Example
Let's see a basic Get query in action. This Python code connects to your Weaviate instance and fetches the title and content of all Article objects.
(Ensure you have a Weaviate instance running locally at http://localhost:8080 and an 'Article' class with some data.)
import weaviate
# Connect to your Weaviate instance
# For local: http://localhost:8080
client = weaviate.Client(url="http://localhost:8080")
# Perform a basic Get query for 'Article' objects
try:
response = client.query.get("Article", ["title", "content"]).do()
print("--- Retrieved Articles ---")
for article in response["data"]["Get"]["Article"]:
print(f"Title: {article['title']}")
except Exception as e:
print(f"Error during query: {e}")Filtering Data with 'where'
Often, you don't want all objects, but specific ones. The where filter allows you to add conditions to your queries, narrowing down the results.
- You can filter by property values (text, number, boolean, date).
- Use operators like
Equal,Like,GreaterThan, etc. - Combine multiple conditions with
_andor_orclauses.
Filter by Property Value
This example shows how to use the where filter to find articles written by a specific author. We'll look for articles where the author property matches 'Jane Doe'.
import weaviate
client = weaviate.Client(url="http://localhost:8080")
# Define the 'where' filter
where_filter = {
"path": ["author"],
"operator": "Equal",
"valueText": "Jane Doe"
}
# Perform the Get query with the filter
try:
response = client.query.get("Article", ["title", "author"])
.with_where(where_filter).do()
print("--- Articles by Jane Doe ---")
for article in response["data"]["Get"]["Article"]:
print(f"Title: {article['title']}, Author: {article['author']}")
except Exception as e:
print(f"Error during query: {e}")Retrieving Vector Embeddings
Weaviate stores a vector embedding for each object, representing its semantic meaning. You can retrieve this vector directly as part of your GraphQL query.
To do this, you use the _additional { vector } clause. This is useful for debugging, understanding your data, or performing custom operations outside Weaviate.
Get Vector Embedding
Here's how to fetch the vector embedding along with other properties. We'll get the title and the vector for the first article found.
import weaviate
client = weaviate.Client(url="http://localhost:8080")
# Query for a title and its vector
try:
response = client.query.get("Article", ["title"])
.with_additional("vector")
.with_limit(1).do()
print("--- Article Title and Vector ---")
if response["data"]["Get"]["Article"]:
article = response["data"]["Get"]["Article"][0]
print(f"Title: {article['title']}")
print(f"Vector (first 5 elements): {article['_additional']['vector'][:5]}...")
else:
print("No articles found.")
except Exception as e:
print(f"Error during query: {e}")Powerful Semantic Search
One of Weaviate's core strengths is semantic search. Instead of keyword matching, it finds data objects based on their meaning, even if the exact words aren't present.
This is achieved using the nearText operator. You provide 'concepts' (text) and Weaviate uses them to find the most semantically similar objects in your database.
Find Similar Articles
Let's perform a semantic search to find articles related to 'machine learning applications'. Notice how we use with_near_text and provide our query concepts.
import weaviate
client = weaviate.Client(url="http://localhost:8080")
# Define the concepts for semantic search
concepts = ["machine learning applications"]
# Perform a nearText query
try:
response = client.query.get("Article", ["title", "content"])
.with_near_text({"concepts": concepts})
.with_limit(3).do()
print("--- Articles similar to 'machine learning applications' ---")
for article in response["data"]["Get"]["Article"]:
print(f"Title: {article['title']}")
except Exception as e:
print(f"Error during query: {e}")GraphQL Query Challenge
You've learned about various ways to query data in Weaviate using GraphQL.
Which of the following GraphQL query operations is specifically used to find data objects that are semantically similar to a given text concept?
Weaviate Queries Recap
Great job! You've mastered the essentials of Weaviate's powerful GraphQL API:
- The
Getoperation retrieves data objects and their properties. - The
wherefilter allows you to apply precise conditions to your searches. - You can explicitly fetch an object's vector embedding using
_additional { vector }. - The
nearTextoperator powers semantic search, finding items based on meaning.
These tools enable you to efficiently retrieve and explore your vector data in Weaviate!
자주 묻는 질문
“Weaviate GraphQL 질의” 강의는 무료인가요?
네 — “Weaviate GraphQL 질의” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Vector Databases: Pinecone, Weaviate & pgvector 강의 전체를 잠금 해제할 수 있습니다. Vector Databases: Pinecone, Weaviate & pgvector 강의에는 총 4개의 강의가 포함되어 있습니다.
“Weaviate GraphQL 질의”에서 뭘 배우나요?
강력한 GraphQL API를 사용하여 의미 검색과 데이터 검색을 수행하도록 Weaviate 데이터를 질의하는 방법을 익힙니다. 브라우저에서 직접 실행하는 실습 코드로 Vector Databases: Pinecone, Weaviate & pgvector을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Vector Databases: Pinecone, Weaviate & pgvector을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Vector Databases: Pinecone, Weaviate & pgvector은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“Weaviate GraphQL 질의” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Vector Databases: Pinecone, Weaviate & pgvector 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Vector Databases: Pinecone, Weaviate & pgvector 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Weaviate 스키마 정의
- 데이터 객체 가져오기
- Weaviate GraphQL 질의
- 벡터화 모듈 및 자동 임베딩