I've populated a Weaviate Cloud Cluster by following the steps in the quick start manual.
I have imported data and the client connection works.
Then for the ask
function, I've implemented the following:
export async function question(collection: Collections, question: string) {
await client.graphql
.get()
.withClassName(collection)
.withAsk({ question })
.withFields('memberName _additional { answer { hasAnswer property result startPosition endPosition } }')
.withLimit(5)
.do()
}
question(Collections.TeamMember, 'Who has painting as a hobby?')
.then((result) => { console.log(result) });
This will return undefined
. I was expecting it to return Sarah Mitchell
.
Additional info:
Schema
I have manually created a schema so that qna-openai
could be added to the moduleConfig
as described here:
export async function addClassToSchema(classObject: object) {
const res = await client.schema.classCreator().withClass(classObject).do();
}
The class object:
{
"class": "TeamMember",
"vectorizer": "text2vec-openai",
"moduleConfig": {
"text2vec-openai": {},
"qna-openai": {
"model": "text-davinci-002",
"maxTokens": 16,
"temperature": 0.0,
"topP": 1,
"frequencyPenalty": 0.0,
"presencePenalty": 0.0
}
},
"properties": [
{
"name": "teamName",
"dataType": ["text"]
},
{
"name": "memberName",
"dataType": ["text"]
},
{
"name": "jobDescription",
"dataType": ["text"]
},
{
"name": "responsibilities",
"dataType": ["text"]
},
{
"name": "education",
"dataType": ["text"]
},
{
"name": "hobbies",
"dataType": ["text"]
}
]
}
When I GET https://test-cluster-name.weaviate.network/v1/schema I get the following response:
{
"classes": [
{
"class": "TeamMember",
"invertedIndexConfig": {
"bm25": {
"b": 0.75,
"k1": 1.2
},
"cleanupIntervalSeconds": 60,
"stopwords": {
"additions": null,
"preset": "en",
"removals": null
}
},
"moduleConfig": {
"qna-openai": {
"frequencyPenalty": 0,
"maxTokens": 16,
"model": "text-davinci-002",
"presencePenalty": 0,
"temperature": 0,
"topP": 1
},
"text2vec-openai": {
"baseURL": "https://api.openai.com",
"model": "ada",
"modelVersion": "002",
"type": "text",
"vectorizeClassName": true
}
},
"multiTenancyConfig": {
"enabled": false
},
"properties": [
{
"dataType": [
"text"
],
"indexFilterable": true,
"indexSearchable": true,
"moduleConfig": {
"text2vec-openai": {
"skip": false,
"vectorizePropertyName": false
}
},
"name": "teamName",
"tokenization": "word"
},
{
"dataType": [
"text"
],
"indexFilterable": true,
"indexSearchable": true,
"moduleConfig": {
"text2vec-openai": {
"skip": false,
"vectorizePropertyName": false
}
},
"name": "memberName",
"tokenization": "word"
},
{
"dataType": [
"text"
],
"indexFilterable": true,
"indexSearchable": true,
"moduleConfig": {
"text2vec-openai": {
"skip": false,
"vectorizePropertyName": false
}
},
"name": "jobDescription",
"tokenization": "word"
},
{
"dataType": [
"text"
],
"indexFilterable": true,
"indexSearchable": true,
"moduleConfig": {
"text2vec-openai": {
"skip": false,
"vectorizePropertyName": false
}
},
"name": "responsibilities",
"tokenization": "word"
},
{
"dataType": [
"text"
],
"indexFilterable": true,
"indexSearchable": true,
"moduleConfig": {
"text2vec-openai": {
"skip": false,
"vectorizePropertyName": false
}
},
"name": "education",
"tokenization": "word"
},
{
"dataType": [
"text"
],
"indexFilterable": true,
"indexSearchable": true,
"moduleConfig": {
"text2vec-openai": {
"skip": false,
"vectorizePropertyName": false
}
},
"name": "hobbies",
"tokenization": "word"
}
],
"replicationConfig": {
"factor": 1
},
"shardingConfig": {
"virtualPerPhysical": 128,
"desiredCount": 1,
"actualCount": 1,
"desiredVirtualCount": 128,
"actualVirtualCount": 128,
"key": "_id",
"strategy": "hash",
"function": "murmur3"
},
"vectorIndexConfig": {
"skip": false,
"cleanupIntervalSeconds": 300,
"maxConnections": 64,
"efConstruction": 128,
"ef": -1,
"dynamicEfMin": 100,
"dynamicEfMax": 500,
"dynamicEfFactor": 8,
"vectorCacheMaxObjects": 1000000000000,
"flatSearchCutoff": 40000,
"distance": "cosine",
"pq": {
"enabled": false,
"bitCompression": false,
"segments": 0,
"centroids": 256,
"trainingLimit": 100000,
"encoder": {
"type": "kmeans",
"distribution": "log-normal"
}
}
},
"vectorIndexType": "hnsw",
"vectorizer": "text2vec-openai"
}
]
}
objects
Then imported a list of members to the Weaviate instance.
export async function teamMembersImport() {
let batcher = client.batch.objectsBatcher();
// When importing the teamsJson, or when the teamsJson becomes large,
// implement batching system as per example on https://weaviate.io/developers/weaviate/quickstart#step-5-add-objects
for (const team of teamsJson) {
const memberObjects = team.members.map((teamMember) => ({
class: 'TeamMember',
properties: {
teamName: team.teamName,
memberName: teamMember.memberName,
jobDescription: teamMember.jobDescription,
responsibilities: teamMember.responsibilities,
education: teamMember.education,
hobbies: teamMember.hobbies,
}
}));
batcher.withObjects(...memberObjects);
}
await batcher.do().then((batchResponse) => {
batchResponse.map((weaviateObjectsGet) => {
if (weaviateObjectsGet.result.status === 'FAILED') {
console.log(weaviateObjectsGet.result.errors);
return;
}
if (weaviateObjectsGet.result.status === 'SUCCESS') {
console.log(`added teamMember ${weaviateObjectsGet.properties.memberName} to ${weaviateObjectsGet.class}`)
}
});
});
}
A GET https://test-cluster-name.weaviate.network/v1/objects will produce the following response:
{
"deprecations": null,
"objects": [
{
"class": "TeamMember",
"creationTimeUnix": 1699264642221,
"id": "0e479bb5-f2c8-4cc1-bc6d-06f298871356",
"lastUpdateTimeUnix": 1699264642221,
"properties": {
"education": "Experienced software engineer.",
"hobbies": "Dedicated marathon runner.",
"jobDescription": "Lead Software Engineer",
"memberName": "Mark Williams",
"responsibilities": "Lead software development and ensure quality.",
"teamName": "The Tech Innovators"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642221,
"id": "217de80d-13b5-4e7d-9757-b8c1c2502e39",
"lastUpdateTimeUnix": 1699264642221,
"properties": {
"education": "Ph.D. in Engineering",
"hobbies": "Avid hiker and explorer of national parks.",
"jobDescription": "Senior Innovation Analyst",
"memberName": "John Porter",
"responsibilities": "Research emerging trends and technologies.",
"teamName": "The Innovation Catalysts"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642220,
"id": "60fad861-24fc-4f91-949a-c34667251084",
"lastUpdateTimeUnix": 1699264642220,
"properties": {
"education": "Market research professional.",
"hobbies": "Self-taught guitarist and musician.",
"jobDescription": "Market Research Analyst",
"memberName": "Michael Lee",
"responsibilities": "Gather and analyze market data for insights.",
"teamName": "The Marketing Mavericks"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642221,
"id": "7ac2c278-79f8-4e39-bb74-6443c9e45ab6",
"lastUpdateTimeUnix": 1699264642221,
"properties": {
"education": "Fluent in three languages, including Spanish.",
"hobbies": "Amateur photographer and participates in local exhibitions.",
"jobDescription": "Innovation Coordinator",
"memberName": "Maria Rodriguez",
"responsibilities": "Project management and execution.",
"teamName": "The Innovation Catalysts"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642220,
"id": "8a3943f4-5f89-4e12-8b17-2fb9bd82f2d1",
"lastUpdateTimeUnix": 1699264642220,
"properties": {
"education": "IT specialist with a passion for music.",
"hobbies": "Skilled pianist and volunteer music instructor.",
"jobDescription": "IT Support Specialist",
"memberName": "Sarah Kim",
"responsibilities": "Provide technical support and maintain IT infrastructure.",
"teamName": "The Tech Innovators"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642220,
"id": "9d5afe43-4dc4-4985-b5bf-94685b5fe77e",
"lastUpdateTimeUnix": 1699264642220,
"properties": {
"education": "Advocate for women in technology.",
"hobbies": "Competitive chess player and marathon runner.",
"jobDescription": "Chief Technology Officer (CTO)",
"memberName": "Lisa Chen",
"responsibilities": "Define technology strategy and oversee product development.",
"teamName": "The Tech Innovators"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642220,
"id": "c918ef93-ad43-401d-a641-6dd5d9c670e8",
"lastUpdateTimeUnix": 1699264642220,
"properties": {
"education": "Published author of a poetry book.",
"hobbies": "Participates in open-mic events and believes in storytelling.",
"jobDescription": "Content Manager",
"memberName": "Emily Collins",
"responsibilities": "Create and manage content for marketing channels.",
"teamName": "The Marketing Mavericks"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642220,
"id": "eca76bea-3663-421a-918d-4e7d3bdea231",
"lastUpdateTimeUnix": 1699264642220,
"properties": {
"education": "Marketing professional with years of experience.",
"hobbies": "Mentors young professionals and coffee enthusiast.",
"jobDescription": "Marketing Director",
"memberName": "David Johnson",
"responsibilities": "Develop and implement marketing strategy.",
"teamName": "The Marketing Mavericks"
},
"vectorWeights": null
},
{
"class": "TeamMember",
"creationTimeUnix": 1699264642221,
"id": "fed0db0d-2456-48a4-8aef-4c7307381a28",
"lastUpdateTimeUnix": 1699264642221,
"properties": {
"education": "Master's degree in Business Administration",
"hobbies": "Passionate about art and volunteers as a painting instructor.",
"jobDescription": "Team Leader",
"memberName": "Sarah Mitchell",
"responsibilities": "Drive innovation and foster a culture of creativity.",
"teamName": "The Innovation Catalysts"
},
"vectorWeights": null
}
],
"totalResults": 9
}
Seems you're not returning anything from the
question
function. You are indeed doing the call to Weaviate, but not returning anything.