Skip to content

Commit 2d58646

Browse files
authored
Merge pull request #217 from weaviate/client-libraries-beta
[New docs] Java v6 & C# client docs
2 parents e2394d6 + eb739e0 commit 2d58646

File tree

154 files changed

+19856
-2501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+19856
-2501
lines changed

.vscode/java-format-settings.xml

Lines changed: 378 additions & 0 deletions
Large diffs are not rendered by default.

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
"other": "on",
1010
"comments": "inline",
1111
"strings": "inline"
12-
}
12+
},
13+
"editor.defaultFormatter": "esbenp.prettier-vscode"
14+
},
15+
"[mdx]": {
16+
"editor.defaultFormatter": "esbenp.prettier-vscode"
1317
},
1418
"files.associations": {
1519
"*.mdx": "markdown"
@@ -108,4 +112,5 @@
108112
"editor.insertSpaces": true
109113
},
110114
"java.configuration.updateBuildConfiguration": "interactive",
115+
"java.compile.nullAnalysis.mode": "automatic",
111116
}

_includes/code/automated-testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from weaviate.classes.init import Auth
55

66
# Get credentials from environment variables
7-
wcd_url = os.environ["WEAVIATE_HOST"]
7+
wcd_url = os.environ["WEAVIATE_URL"]
88
wcd_api_key = os.environ["WEAVIATE_API_KEY"]
99
openai_api = os.environ["OPENAI_APIKEY"]
1010

_includes/code/client-libraries/get_started.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
client = weaviate.connect_to_local()
88
# highlight-end
99

10+
# END GetStarted
11+
client.collections.delete("Question") # Clean up from previous runs
12+
# START GetStarted
1013
# highlight-start
1114
questions = client.collections.create(
1215
name="Question",
13-
vector_config=Configure.Vectors.text2vec_ollama(), # Configure the Ollama embedding model
16+
vector_config=Configure.Vectors.text2vec_ollama(
17+
api_endpoint="http://ollama:11434", # If using Docker you might need: http://host.docker.internal:11434
18+
model="nomic-embed-text", # The model to use
19+
), # Configure the Ollama embedding model
1420
)
1521
# highlight-end
1622

@@ -38,6 +44,10 @@
3844
if failed_objects:
3945
print(f"Number of failed imports: {len(failed_objects)}")
4046
print(f"First failed object: {failed_objects[0]}")
47+
# END GetStarted
48+
import time
49+
time.sleep(2) # Wait for the batch to be indexed
50+
# START GetStarted
4151

4252
# highlight-start
4353
response = questions.query.near_text(query="biology", limit=2)
Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
import Tabs from '@theme/Tabs';
2-
import TabItem from '@theme/TabItem';
3-
import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock';
1+
import Tabs from "@theme/Tabs";
2+
import TabItem from "@theme/TabItem";
3+
import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock";
44

5-
import PyV4Code from '!!raw-loader!/_includes/code/connections/connect-python-v4.py';
6-
import TsV3Code from '!!raw-loader!/_includes/code/connections/connect-ts-v3.ts';
5+
import PyV4Code from "!!raw-loader!/_includes/code/connections/connect-python-v4.py";
6+
import TsV3Code from "!!raw-loader!/_includes/code/connections/connect-ts-v3.ts";
7+
import JavaV6Code from "!!raw-loader!/_includes/code/java-v6/src/test/java/ConnectionTest.java";
8+
import CSharpCode from "!!raw-loader!/_includes/code/csharp/ConnectionTest.cs";
79

810
<Tabs className="code" groupId="languages">
9-
<TabItem value="py" label="Python">
10-
<FilteredTextBlock
11-
text={PyV4Code}
12-
startMarker="# START TimeoutWCD"
13-
endMarker="# END TimeoutWCD"
14-
language="py"
15-
/>
16-
</TabItem>
17-
<TabItem value="ts" label="JavaScript/TypeScript">
18-
<FilteredTextBlock
19-
text={TsV3Code}
20-
startMarker="// START TimeoutWCD"
21-
endMarker="// END TimeoutWCD"
22-
language="ts"
23-
/>
24-
</TabItem>
11+
<TabItem value="py" label="Python">
12+
<FilteredTextBlock
13+
text={PyV4Code}
14+
startMarker="# START TimeoutWCD"
15+
endMarker="# END TimeoutWCD"
16+
language="py"
17+
/>
18+
</TabItem>
19+
<TabItem value="ts" label="JavaScript/TypeScript">
20+
<FilteredTextBlock
21+
text={TsV3Code}
22+
startMarker="// START TimeoutWCD"
23+
endMarker="// END TimeoutWCD"
24+
language="ts"
25+
/>
26+
</TabItem>
27+
<TabItem value="java6" label="Java v6 (Beta)">
28+
<FilteredTextBlock
29+
text={JavaV6Code}
30+
startMarker="// START TimeoutWCD"
31+
endMarker="// END TimeoutWCD"
32+
language="java"
33+
/>
34+
</TabItem>
35+
<TabItem value="csharp" label="C# (Beta)">
36+
<FilteredTextBlock
37+
text={CSharpCode}
38+
startMarker="// START TimeoutWCD"
39+
endMarker="// END TimeoutWCD"
40+
language="csharp"
41+
/>
42+
</TabItem>
2543
</Tabs>
Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
import Tabs from '@theme/Tabs';
2-
import TabItem from '@theme/TabItem';
3-
import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock';
1+
import Tabs from "@theme/Tabs";
2+
import TabItem from "@theme/TabItem";
3+
import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock";
44

5-
import PyV4Code from '!!raw-loader!/_includes/code/connections/connect-python-v4.py';
6-
import TsV3Code from '!!raw-loader!/_includes/code/connections/connect-ts-v3.ts';
5+
import PyV4Code from "!!raw-loader!/_includes/code/connections/connect-python-v4.py";
6+
import TsV3Code from "!!raw-loader!/_includes/code/connections/connect-ts-v3.ts";
7+
import JavaV6Code from "!!raw-loader!/_includes/code/java-v6/src/test/java/ConnectionTest.java";
8+
import CSharpCode from "!!raw-loader!/_includes/code/csharp/ConnectionTest.cs";
79

810
<Tabs className="code" groupId="languages">
9-
<TabItem value="py" label="Python">
10-
<FilteredTextBlock
11-
text={PyV4Code}
12-
startMarker="# START TimeoutCustom"
13-
endMarker="# END TimeoutCustom"
14-
language="py"
15-
/>
16-
</TabItem>
17-
<TabItem value="ts" label="JavaScript/TypeScript">
18-
<FilteredTextBlock
19-
text={TsV3Code}
20-
startMarker="// START TimeoutCustom"
21-
endMarker="// END TimeoutCustom"
22-
language="ts"
23-
/>
24-
</TabItem>
11+
<TabItem value="py" label="Python">
12+
<FilteredTextBlock
13+
text={PyV4Code}
14+
startMarker="# START TimeoutCustom"
15+
endMarker="# END TimeoutCustom"
16+
language="py"
17+
/>
18+
</TabItem>
19+
<TabItem value="ts" label="JavaScript/TypeScript">
20+
<FilteredTextBlock
21+
text={TsV3Code}
22+
startMarker="// START TimeoutCustom"
23+
endMarker="// END TimeoutCustom"
24+
language="ts"
25+
/>
26+
</TabItem>
27+
<TabItem value="java6" label="Java v6 (Beta)">
28+
<FilteredTextBlock
29+
text={JavaV6Code}
30+
startMarker="// START TimeoutCustom"
31+
endMarker="// END TimeoutCustom"
32+
language="java"
33+
/>
34+
</TabItem>
35+
<TabItem value="csharp" label="C# (Beta)">
36+
<FilteredTextBlock
37+
text={CSharpCode}
38+
startMarker="// START TimeoutCustom"
39+
endMarker="// END TimeoutCustom"
40+
language="csharp"
41+
/>
42+
</TabItem>
2543
</Tabs>
Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
1-
import Tabs from '@theme/Tabs';
2-
import TabItem from '@theme/TabItem';
3-
import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock';
4-
5-
import PyV4Code from '!!raw-loader!/_includes/code/connections/connect-python-v4.py';
6-
import TsV3Code from '!!raw-loader!/_includes/code/connections/connect-ts-v3.ts';
1+
import Tabs from "@theme/Tabs";
2+
import TabItem from "@theme/TabItem";
3+
import FilteredTextBlock from "@site/src/components/Documentation/FilteredTextBlock";
74

5+
import PyV4Code from "!!raw-loader!/_includes/code/connections/connect-python-v4.py";
6+
import TsV3Code from "!!raw-loader!/_includes/code/connections/connect-ts-v3.ts";
7+
import JavaV6Code from "!!raw-loader!/_includes/code/java-v6/src/test/java/ConnectionTest.java";
8+
import CSharpCode from "!!raw-loader!/_includes/code/csharp/ConnectionTest.cs";
89

910
<Tabs className="code" groupId="languages">
10-
<TabItem value="py" label="Python">
11-
<FilteredTextBlock
12-
text={PyV4Code}
13-
startMarker="# START TimeoutLocal"
14-
endMarker="# END TimeoutLocal"
15-
language="py"
16-
/>
17-
</TabItem>
18-
<TabItem value="ts" label="JavaScript/TypeScript">
19-
<FilteredTextBlock
20-
text={TsV3Code}
21-
startMarker="// START TimeoutLocal"
22-
endMarker="// END TimeoutLocal"
23-
language="ts"
24-
/>
25-
</TabItem>
11+
<TabItem value="py" label="Python">
12+
<FilteredTextBlock
13+
text={PyV4Code}
14+
startMarker="# START TimeoutLocal"
15+
endMarker="# END TimeoutLocal"
16+
language="py"
17+
/>
18+
</TabItem>
19+
<TabItem value="ts" label="JavaScript/TypeScript">
20+
<FilteredTextBlock
21+
text={TsV3Code}
22+
startMarker="// START TimeoutLocal"
23+
endMarker="// END TimeoutLocal"
24+
language="ts"
25+
/>
26+
</TabItem>
27+
<TabItem value="java6" label="Java v6 (Beta)">
28+
<FilteredTextBlock
29+
text={JavaV6Code}
30+
startMarker="// START TimeoutLocal"
31+
endMarker="// END TimeoutLocal"
32+
language="java"
33+
/>
34+
</TabItem>
35+
<TabItem value="csharp" label="C# (Beta)">
36+
<FilteredTextBlock
37+
text={CSharpCode}
38+
startMarker="// START TimeoutLocal"
39+
endMarker="// END TimeoutLocal"
40+
language="csharp"
41+
/>
42+
</TabItem>
2643
</Tabs>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Xunit;
2+
using Weaviate.Client;
3+
using Weaviate.Client.Models;
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
namespace WeaviateProject.Tests;
8+
9+
public class ConfigureBQTest : IAsyncLifetime
10+
{
11+
private WeaviateClient client;
12+
private const string COLLECTION_NAME = "MyCollection";
13+
14+
// Runs before each test
15+
public async Task InitializeAsync()
16+
{
17+
// START ConnectCode
18+
// Note: The C# client doesn't support setting headers like 'X-OpenAI-Api-Key' via the constructor for local connections.
19+
// This must be configured in Weaviate's environment variables.
20+
client = new WeaviateClient(new ClientConfiguration { RestAddress = "localhost", RestPort = 8080 });
21+
// END ConnectCode
22+
23+
// Clean slate for each test
24+
if (await client.Collections.Exists(COLLECTION_NAME))
25+
{
26+
await client.Collections.Delete(COLLECTION_NAME);
27+
}
28+
}
29+
30+
// Runs after each test
31+
public Task DisposeAsync()
32+
{
33+
// No action needed here, as cleanup happens in InitializeAsync before the next test.
34+
return Task.CompletedTask;
35+
}
36+
37+
[Fact]
38+
public async Task TestEnableBQ()
39+
{
40+
// START EnableBQ
41+
await client.Collections.Create(new CollectionConfig
42+
{
43+
Name = "MyCollection",
44+
Properties = [Property.Text("title")],
45+
VectorConfig = new VectorConfig(
46+
"default",
47+
new Vectorizer.Text2VecTransformers(),
48+
new VectorIndex.HNSW
49+
{
50+
// highlight-start
51+
Quantizer = new VectorIndex.Quantizers.BQ()
52+
// highlight-end
53+
}
54+
)
55+
});
56+
// END EnableBQ
57+
}
58+
59+
[Fact]
60+
public async Task TestUpdateSchema()
61+
{
62+
// Note: Updating quantization settings on an existing collection is not supported by Weaviate
63+
// and will result in an error, as noted in the Java test. This test demonstrates the syntax for attempting the update.
64+
var collection = await client.Collections.Create(new CollectionConfig
65+
{
66+
Name = "MyCollection",
67+
Properties = [Property.Text("title")],
68+
VectorConfig = new VectorConfig("default", new Vectorizer.Text2VecTransformers())
69+
});
70+
71+
// START UpdateSchema
72+
await collection.Config.Update(c =>
73+
{
74+
var vectorConfig = c.VectorConfig["default"];
75+
vectorConfig.VectorIndexConfig.UpdateHNSW(h => h.Quantizer = new VectorIndex.Quantizers.BQ());
76+
});
77+
// END UpdateSchema
78+
}
79+
80+
[Fact]
81+
public async Task TestBQWithOptions()
82+
{
83+
// START BQWithOptions
84+
await client.Collections.Create(new CollectionConfig
85+
{
86+
Name = "MyCollection",
87+
Properties = [Property.Text("title")],
88+
VectorConfig = new VectorConfig(
89+
"default",
90+
new Vectorizer.Text2VecTransformers(),
91+
// highlight-start
92+
new VectorIndex.HNSW
93+
{
94+
VectorCacheMaxObjects = 100000,
95+
Quantizer = new VectorIndex.Quantizers.BQ
96+
{
97+
Cache = true,
98+
RescoreLimit = 200
99+
}
100+
}
101+
// highlight-end
102+
)
103+
});
104+
// END BQWithOptions
105+
}
106+
}

0 commit comments

Comments
 (0)