Skip to content

Commit 16f0d6a

Browse files
authored
Merge pull request #227 from weaviate/v1-34/contextual-ai-models
Add Contextual AI doc draft
2 parents dd535d0 + cd6ac2a commit 16f0d6a

21 files changed

+816
-10
lines changed
47.4 KB
Loading
47.3 KB
Loading
47.6 KB
Loading
50.9 KB
Loading

docs/weaviate/model-providers/_includes/provider.connect.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
# Recommended: save sensitive data as environment variables
2626
cohere_key = os.getenv("COHERE_APIKEY")
2727
# END CohereInstantiation
28+
# START ContextualAIInstantiation
29+
# Recommended: save sensitive data as environment variables
30+
contextual_key = os.getenv("CONTEXTUAL_API_KEY")
31+
# END ContextualAIInstantiation
2832
# START DatabricksInstantiation
2933
# Recommended: save sensitive data as environment variables
3034
databricks_token = os.getenv("DATABRICKS_TOKEN")
@@ -100,6 +104,9 @@
100104
# START CohereInstantiation
101105
"X-Cohere-Api-Key": cohere_key,
102106
# END CohereInstantiation
107+
# START ContextualAIInstantiation
108+
"X-ContextualAI-Api-Key": contextual_key,
109+
# END ContextualAIInstantiation
103110
# START DatabricksInstantiation
104111
"X-Databricks-Token": databricks_token,
105112
# END DatabricksInstantiation

docs/weaviate/model-providers/_includes/provider.connect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const aws_secret_key = process.env.AWS_SECRET_KEY || ''; // Replace with your A
1616
// START CohereInstantiation
1717
const cohereApiKey = process.env.COHERE_APIKEY || ''; // Replace with your inference API key
1818
// END CohereInstantiation
19+
// START ContextualAIInstantiation
20+
const contextualApiKey = process.env.CONTEXTUAL_API_KEY || ''; // Replace with your inference API key
21+
// END ContextualAIInstantiation
1922
// START DatabricksInstantiation
2023
const databricksToken = process.env.DATABRICKS_TOKEN || ''; // Replace with your inference API key
2124
// END DatabricksInstantiation
@@ -78,6 +81,9 @@ const client = await weaviate.connectToWeaviateCloud(
7881
// START CohereInstantiation
7982
'X-Cohere-Api-Key': cohereApiKey,
8083
// END CohereInstantiation
84+
// START ContextualAIInstantiation
85+
'X-ContextualAI-Api-Key': contextualApiKey,
86+
// END ContextualAIInstantiation
8187
// START DatabricksInstantiation
8288
'X-Databricks-Token': databricksToken,
8389
// END DatabricksInstantiation

docs/weaviate/model-providers/_includes/provider.generative.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,90 @@ def import_data():
421421
# clean up
422422
client.collections.delete("DemoCollection")
423423

424+
# START BasicGenerativeContextualAI
425+
from weaviate.classes.config import Configure
426+
427+
client.collections.create(
428+
"DemoCollection",
429+
# highlight-start
430+
generative_config=Configure.Generative.contextualai()
431+
# highlight-end
432+
# Additional parameters not shown
433+
)
434+
# END BasicGenerativeContextualAI
435+
436+
# clean up
437+
client.collections.delete("DemoCollection")
438+
439+
# START GenerativeContextualAICustomModel
440+
from weaviate.classes.config import Configure
441+
442+
client.collections.create(
443+
"DemoCollection",
444+
# highlight-start
445+
generative_config=Configure.Generative.contextualai(
446+
model="v2"
447+
)
448+
# highlight-end
449+
# Additional parameters not shown
450+
)
451+
# END GenerativeContextualAICustomModel
452+
453+
# clean up
454+
client.collections.delete("DemoCollection")
455+
456+
457+
# START FullGenerativeContextualAI
458+
from weaviate.classes.config import Configure
459+
460+
client.collections.create(
461+
"DemoCollection",
462+
# highlight-start
463+
generative_config=Configure.Generative.contextualai(
464+
# # These parameters are optional
465+
# model="v2",
466+
# temperature=0.7,
467+
# max_tokens=1024,
468+
# top_p=0.9,
469+
# system_prompt="You are a helpful assistant"
470+
# avoid_commentary=True,
471+
)
472+
# highlight-end
473+
# Additional parameters not shown
474+
)
475+
# END FullGenerativeContextualAI
476+
477+
# clean up
478+
client.collections.delete("DemoCollection")
479+
import_data()
480+
481+
# START RuntimeModelSelectionContextualAI
482+
from weaviate.classes.config import Configure
483+
from weaviate.classes.generate import GenerativeConfig
484+
485+
collection = client.collections.use("DemoCollection")
486+
response = collection.generate.near_text(
487+
query="A holiday film",
488+
limit=2,
489+
grouped_task="Write a tweet promoting these two movies",
490+
# highlight-start
491+
generative_provider=GenerativeConfig.contextualai(
492+
# # These parameters are optional
493+
# model="v2",
494+
# temperature=0.7,
495+
# max_tokens=1024,
496+
# top_p=0.9,
497+
# system_prompt="You are a helpful assistant"
498+
# avoid_commentary=True,
499+
),
500+
# Additional parameters not shown
501+
# highlight-end
502+
)
503+
# END RuntimeModelSelectionContextualAI
504+
505+
# clean up
506+
client.collections.delete("DemoCollection")
507+
424508
# START BasicGenerativeDatabricks
425509
from weaviate.classes.config import Configure
426510

docs/weaviate/model-providers/_includes/provider.generative.ts

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import assert from 'assert';
55
// ================================
66
import weaviate from 'weaviate-client';
77

8-
// START RuntimeModelSelectionAnthropic // START WorkingWithImagesAnthropic // START WorkingWithImagesAWS // START WorkingWithImagesGoogle // START WorkingWithImagesOpenAI // START RuntimeModelSelectionAnyscale // START RuntimeModelSelectionMistral // START RuntimeModelSelectionOpenAI // START RuntimeModelSelectionAWS // START RuntimeModelSelectionCohere // START RuntimeModelSelectionDatabricks // START RuntimeModelSelectionFriendliAI // START RuntimeModelSelectionGoogle // START RuntimeModelSelectionNVIDIA // START RuntimeModelSelectionKubeAI // START RuntimeModelSelectionAzureOpenAI // START RuntimeModelSelectionOllama // START RuntimeModelSelectionxAI
8+
// START RuntimeModelSelectionAnthropic // START WorkingWithImagesAnthropic // START WorkingWithImagesAWS // START WorkingWithImagesGoogle // START WorkingWithImagesOpenAI // START RuntimeModelSelectionAnyscale // START RuntimeModelSelectionMistral // START RuntimeModelSelectionOpenAI // START RuntimeModelSelectionAWS // START RuntimeModelSelectionCohere // START RuntimeModelSelectionDatabricks // START RuntimeModelSelectionFriendliAI // START RuntimeModelSelectionGoogle // START RuntimeModelSelectionNVIDIA // START RuntimeModelSelectionKubeAI // START RuntimeModelSelectionAzureOpenAI // START RuntimeModelSelectionOllama // START RuntimeModelSelectionxAI
99
import { generativeParameters } from 'weaviate-client';
1010

11-
// END RuntimeModelSelectionAnthropic // END WorkingWithImagesAnthropic // END WorkingWithImagesAWS // END WorkingWithImagesGoogle // END WorkingWithImagesOpenAI // END RuntimeModelSelectionAnyscale // END RuntimeModelSelectionMistral // END RuntimeModelSelectionOpenAI // END RuntimeModelSelectionAWS // END RuntimeModelSelectionCohere // END RuntimeModelSelectionDatabricks // END RuntimeModelSelectionFriendliAI // END RuntimeModelSelectionGoogle // END RuntimeModelSelectionNVIDIA // END RuntimeModelSelectionKubeAI // END RuntimeModelSelectionAzureOpenAI // END RuntimeModelSelectionOllama // END RuntimeModelSelectionxAI
11+
// END RuntimeModelSelectionAnthropic // END WorkingWithImagesAnthropic // END WorkingWithImagesAWS // END WorkingWithImagesGoogle // END WorkingWithImagesOpenAI // END RuntimeModelSelectionAnyscale // END RuntimeModelSelectionMistral // END RuntimeModelSelectionOpenAI // END RuntimeModelSelectionAWS // END RuntimeModelSelectionCohere // END RuntimeModelSelectionDatabricks // END RuntimeModelSelectionFriendliAI // END RuntimeModelSelectionGoogle // END RuntimeModelSelectionNVIDIA // END RuntimeModelSelectionKubeAI // END RuntimeModelSelectionAzureOpenAI // END RuntimeModelSelectionOllama // END RuntimeModelSelectionxAI
1212

1313
// START WorkingWithImagesAnthropic // START WorkingWithImagesAWS // START WorkingWithImagesGoogle // START WorkingWithImagesOpenAI
1414
function arrayBufferToBase64(buffer: ArrayBuffer): string {
@@ -306,7 +306,7 @@ console.log("Grouped task result:", response.generative?.text)
306306
})();
307307

308308
// Clean up
309-
await client.collections.delete('DemoCollection');
309+
await client.collections.delete('DemoCollection');
310310

311311
// START BasicGenerativeCohere
312312
await client.collections.create({
@@ -377,6 +377,76 @@ response = await myCollection.generate.nearText("A holiday film", {
377377
)
378378
// END RuntimeModelSelectionCohere
379379

380+
// Clean up
381+
await client.collections.delete('DemoCollection');
382+
383+
// START BasicGenerativeContextualAI
384+
await client.collections.create({
385+
name: 'DemoCollection',
386+
// highlight-start
387+
generative: weaviate.configure.generative.contextualai(),
388+
// highlight-end
389+
// Additional parameters not shown
390+
});
391+
// END BasicGenerativeContextualAI
392+
393+
// Clean up
394+
await client.collections.delete('DemoCollection');
395+
396+
// START GenerativeContextualAICustomModel
397+
await client.collections.create({
398+
name: 'DemoCollection',
399+
// highlight-start
400+
generative: weaviate.configure.generative.contextualai({
401+
model: 'v2'
402+
}),
403+
// highlight-end
404+
// Additional parameters not shown
405+
});
406+
// END GenerativeContextualAICustomModel
407+
408+
// Clean up
409+
await client.collections.delete('DemoCollection');
410+
411+
412+
// START FullGenerativeContextualAI
413+
await client.collections.create({
414+
name: 'DemoCollection',
415+
// highlight-start
416+
generative: weaviate.configure.generative.contextualai({
417+
// These parameters are optional
418+
model: 'v2',
419+
// temperature: 0.7,
420+
// maxTokens: 1024,
421+
// topP: 0.9,
422+
// systemPrompt: 'You are a helpful assistant',
423+
// avoidCommentary: true,
424+
}),
425+
// highlight-end
426+
// Additional parameters not shown
427+
});
428+
// END FullGenerativeContextualAI
429+
430+
// START RuntimeModelSelectionContextualAI
431+
response = await myCollection.generate.nearText("A holiday film", {
432+
// highlight-start
433+
groupedTask: "Write a tweet promoting these two movies",
434+
config: generativeParameters.contextualai({
435+
// These parameters are optional
436+
// model: 'v2',
437+
// temperature: 0.7,
438+
// maxTokens: 1024,
439+
// topP: 0.9,
440+
// systemPrompt: 'You are a helpful assistant',
441+
// avoidCommentary: true,
442+
}),
443+
// highlight-end
444+
}, {
445+
limit: 2,
446+
}
447+
// Additional parameters not shown
448+
)
449+
// END RuntimeModelSelectionContextualAI
380450

381451
// Clean up
382452
await client.collections.delete('DemoCollection');
@@ -1168,4 +1238,4 @@ for (const obj of groupedTaskResults.objects) {
11681238
client.close();
11691239

11701240
}
1171-
void main()
1241+
void main()

docs/weaviate/model-providers/_includes/provider.reranker.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,40 @@
6060
# Clean up
6161
client.collections.delete("DemoCollection")
6262

63+
# START RerankerContextualAIBasic
64+
from weaviate.classes.config import Configure
65+
66+
client.collections.create(
67+
"DemoCollection",
68+
# highlight-start
69+
reranker_config=Configure.Reranker.contextualai()
70+
# highlight-end
71+
# Additional parameters not shown
72+
)
73+
# END RerankerContextualAIBasic
74+
75+
# Clean up
76+
client.collections.delete("DemoCollection")
77+
78+
# START RerankerContextualAICustomModel
79+
from weaviate.classes.config import Configure
80+
81+
client.collections.create(
82+
"DemoCollection",
83+
# highlight-start
84+
reranker_config=Configure.Reranker.contextualai(
85+
model="ctxl-rerank-v2-instruct-multilingual",
86+
instruction="Prioritize internal sales documents over market analysis reports. More recent documents should be weighted higher.",
87+
top_n=5
88+
)
89+
# highlight-end
90+
# Additional parameters not shown
91+
)
92+
# END RerankerContextualAICustomModel
93+
94+
# Clean up
95+
client.collections.delete("DemoCollection")
96+
6397
# START RerankerJinaAIBasic
6498
from weaviate.classes.config import Configure
6599

docs/weaviate/model-providers/_includes/provider.reranker.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ await client.collections.create({
4141
});
4242
// END RerankerCohereCustomModel
4343

44+
// START RerankerContextualAIBasic
45+
await client.collections.create({
46+
name: 'DemoCollection',
47+
// highlight-start
48+
reranker: weaviate.configure.reranker.contextualai(),
49+
// highlight-end
50+
});
51+
// END RerankerContextualAIBasic
52+
53+
// START RerankerContextualAICustomModel
54+
await client.collections.create({
55+
name: 'DemoCollection',
56+
// highlight-start
57+
reranker: weaviate.configure.reranker.contextualai({
58+
model: 'ctxl-rerank-v2-instruct-multilingual',
59+
instruction: 'Prioritize internal sales documents over market analysis reports. More recent documents should be weighted higher.',
60+
topN: 5,
61+
}),
62+
// highlight-end
63+
});
64+
// END RerankerContextualAICustomModel
65+
4466
// START RerankerJinaAIBasic
4567
await client.collections.create({
4668
name: 'DemoCollection',

0 commit comments

Comments
 (0)