0
0
Prompt Engineering / GenAIml~10 mins

Vector databases (Pinecone, ChromaDB, Weaviate) in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize a Pinecone client with your API key.

Prompt Engineering / GenAI
import pinecone
pinecone.init(api_key=[1])
Drag options to blanks, or click blank then click option'
A12345
B'your-pinecone-api-key'
Cpinecone_key
Dapi_key
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the API key inside quotes.
Using a variable name instead of the actual key string.
2fill in blank
medium

Complete the code to create a new index in Pinecone with dimension 128.

Prompt Engineering / GenAI
pinecone.create_index(name='example-index', dimension=[1])
Drag options to blanks, or click blank then click option'
A512
B64
C128
D256
Attempts:
3 left
💡 Hint
Common Mistakes
Using a dimension that does not match the vector size.
Using a string instead of a number.
3fill in blank
hard

Fix the error in the code to query a Pinecone index for the top 3 similar vectors.

Prompt Engineering / GenAI
index = pinecone.Index('example-index')
query_result = index.query(queries=[query_vector], top_k=[1])
Drag options to blanks, or click blank then click option'
A3
B'3'
Ctop3
D[3]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing '3' as a string instead of integer 3.
Passing a list like [3] instead of an integer.
4fill in blank
hard

Fill both blanks to create a ChromaDB client and add a collection named 'my_collection'.

Prompt Engineering / GenAI
import chromadb
client = chromadb.[1]()
collection = client.[2]('my_collection')
Drag options to blanks, or click blank then click option'
AClient
Bcreate_collection
CCollection
Dget_collection
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_collection() instead of create_collection() to add a new collection.
Using Collection() instead of Client() to create the client.
5fill in blank
hard

Fill all three blanks to initialize a Weaviate client, create a schema, and add a data object.

Prompt Engineering / GenAI
import weaviate
client = weaviate.Client([1])
schema = {
  'classes': [{'class': [2], 'properties': [{'name': 'text', 'dataType': ['string']}]}]
}
client.schema.[3](schema)
Drag options to blanks, or click blank then click option'
A'http://localhost:8080'
B'Document'
Ccreate
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using delete() instead of create() to add the schema.
Using wrong URL or missing quotes.
Using wrong class name or missing quotes.