Skip to content

Commit bd69ace

Browse files
Merge pull request #71 from Build5Nines/dev
add Metadata documentation & LICENSE file reference change for future
2 parents 2c52f2d + 71072c3 commit bd69ace

File tree

8 files changed

+205
-3
lines changed

8 files changed

+205
-3
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Metadata
3+
---
4+
# Metadata
5+
6+
The `Build5Nines.SharpVector` vector database enables semantic search for `Text` that is stored in the database. Being able to semantically search text is an extremely useful way to lookup more information related to the text. For this purpose, `Metadata` is stored alongside the `Text` within the vector database. This way, when `Text` is found when performing a semantic search, then the matching `Metadata` is also retrieved.
7+
8+
## Adding Metadata
9+
10+
The `.AddText` and `.AddTextAsync` methods access 2 arguments:
11+
12+
- `text`: The `Text` that is added to the vector database and has vector embeddings generated for.
13+
- `metadata`: This is additional data / information that is stored alongside the `Text`.
14+
15+
```csharp
16+
vdb.AddText(text, metadata);
17+
18+
await vdb.AddText(text, metadata);
19+
```
20+
21+
## JSON and String Metadata
22+
23+
When using the `BasicMemoryVectorDatabase` class, the `Metadata` values will always be of type `String`. This enables you to store a variety of values here, including:
24+
25+
- **JSON data**: You can serialize any data to a JSON string for storage in the `Metadata` associated with a text item in the database.
26+
- **`String` value**: You can store any other string value as the `Metadata` associated with a text item in the database. This could be a URL, Filename, or other information.
27+
28+
!!! info "OpenAI and Ollama Support"
29+
When working with the [OpenAI](../../embeddings/openai/index.md) `BasicOpenAIMemoryVectorDatabase` and [Ollama](../../embeddings/ollama/index.md) `BasicOllamaMemoryVectorDatabase`, the `Metadata` data type is also `String`.
30+
31+
Here are some examples of storing `string` metadata and retrieving it from the database:
32+
33+
=== "JSON data"
34+
35+
```csharp
36+
// create vector database
37+
var vdb = new BasicMemoryVectorDatabase();
38+
39+
// some text to store in the vector database
40+
var text = "some text value";
41+
// serialize an object to json to store as metadata
42+
var json = JsonSerializer.Serialize(new MyMetadata{
43+
Url = "https://build5nines.com",
44+
Author = "Chris Pietschmann"
45+
});
46+
47+
// Add text with metadata to vector database
48+
vdb.AddText(text, json);
49+
50+
// perform semantic search
51+
var results = vdb.Search("something to search", pageCount: 5);
52+
53+
// Loop through search results
54+
foreach(var item in results.Texts) {
55+
var text = item.Text;
56+
var json = item.Metadata;
57+
var metadata = JsonSerializer.Deserialize<MyMetadata>(json);
58+
59+
// do something with results and metadata
60+
}
61+
```
62+
63+
=== "String value"
64+
65+
```csharp
66+
// create vector database
67+
var vdb = new BasicMemoryVectorDatabase();
68+
69+
// some text to store in the vector database
70+
var text = "some text value";
71+
// some metadata to store
72+
var metadata = "https://build5nines.com";
73+
74+
// Add text with metadata to vector database
75+
vdb.AddText(text, metadata);
76+
77+
// perform semantic search
78+
var results = vdb.Search("something to search", pageCount: 5);
79+
80+
// Loop through search results
81+
foreach(var item in results.Texts) {
82+
var text = item.Text;
83+
var metadata = item.Metadata;
84+
85+
// do something with results and metadata
86+
}
87+
```
88+
89+
## Custom Metadata Type
90+
91+
The `MemoryVectorDatabase<TMetadata>` generic class allows you to create a vector database that uses your own custom class as the metadata by defining that class using generics. This enables you to store a native .NET object as the metadata alongside the text in the vector database.
92+
93+
Here's an example of using the `MemoryVectorDatabase<TMetadata>` with a .NET class for the `Metadata`:
94+
95+
```csharp
96+
// create vector database
97+
var vdb = new MemoryVectorDatabase<MyMetadata>();
98+
99+
// some text to store in the vector database
100+
var text = "some text value";
101+
// an object to store as metadata
102+
var metadata = new MyMetadata{
103+
Url = "https://build5nines.com",
104+
Author = "Chris Pietschmann"
105+
};
106+
107+
// Add text with metadata to vector database
108+
vdb.AddText(text, metadata);
109+
110+
// perform semantic search
111+
var results = vdb.Search("something to search", pageCount: 5);
112+
113+
// Loop through search results
114+
foreach(var item in results.Texts) {
115+
var text = item.Text;
116+
var metadata = item.Metadata;
117+
118+
var url = metadata.Url;
119+
var author = metadata.Author;
120+
121+
// do something with results and metadata
122+
}
123+
```
124+
125+
This will offer better performance with scenarios that require more complex metadata since you no longer need to handle serialization to/from JSON.
126+
127+
!!! info "OpenAI and Ollama Support"
128+
The `OpenAIMemoryVectorDatabase<TMetadata>` and `OllamaMemoryVectorDatabase<TMetadata>` generic classes can also be used to define your own `Metadata` type when working with [OpenAI and Ollama embeddings](../../embeddings/index.md).

docs/mkdocs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ nav:
137137
- Prerequisites: get-started/#prerequisites
138138
- Install Nuget Package: get-started/#install-nuget-package
139139
- Basic Example: get-started/#basic-example
140+
- Metadata:
141+
- get-started/metadata/index.md
142+
- Adding Metadata: get-started/metadata/#adding-metadata
143+
- JSON and String Metadata: get-started/metadata/#json-and-string-metadata
144+
- Custom Metadata Type: get-started/metadata/#custom-metadata-type
145+
140146
- Data Management:
141147
- get-started/data-management/index.md
142148
- Get Text Item Id: get-started/data-management/#get-text-item-id

src/Build5Nines.SharpVector.Ollama/Build5Nines.SharpVector.Ollama.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
<Description>Lightweight In-memory Vector Database to embed in any .NET Applications that integrates with Ollama Embedding models for vector generation.</Description>
1414
<Copyright>Copyright (c) 2025 Build5Nines LLC</Copyright>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
<PackageLicenseUrl>https://github.com/Build5Nines/SharpVector/blob/main/LICENSE</PackageLicenseUrl>
16+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1717
<Authors>Chris Pietschmann</Authors>
1818
<Company>Build5Nines LLC</Company>
1919
<PackageTags>vector;search;database;data;rag;ollama;embeddings;azure;microsoft;</PackageTags>
2020
</PropertyGroup>
2121

2222
<ItemGroup>
2323
<None Include="docs/README.md" Pack="true" PackagePath="\" />
24+
<None Include="docs/LICENSE" Pack="true" PackagePath="\" />
2425
</ItemGroup>
2526

2627
<ItemGroup>
2728
<PackageReference Include="Build5Nines.SharpVector" Version="[2.0.3,3.0.0)" />
29+
<!-- <ProjectReference Include="..\Build5Nines.SharpVector\Build5Nines.SharpVector.csproj" /> -->
2830
</ItemGroup>
2931

3032
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Build5Nines LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/Build5Nines.SharpVector.OpenAI/Build5Nines.SharpVector.OpenAI.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
<Description>Lightweight In-memory Vector Database to embed in any .NET Applications that integrates with OpenAI Embedding model for vector generation.</Description>
1414
<Copyright>Copyright (c) 2025 Build5Nines LLC</Copyright>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
<PackageLicenseUrl>https://github.com/Build5Nines/SharpVector/blob/main/LICENSE</PackageLicenseUrl>
16+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1717
<Authors>Chris Pietschmann</Authors>
1818
<Company>Build5Nines LLC</Company>
1919
<PackageTags>vector;search;database;data;rag;openai;embeddings;azure;microsoft;</PackageTags>
2020
</PropertyGroup>
2121

2222
<ItemGroup>
2323
<None Include="docs/README.md" Pack="true" PackagePath="\" />
24+
<None Include="docs/LICENSE" Pack="true" PackagePath="\" />
2425
</ItemGroup>
2526

2627
<ItemGroup>
2728
<PackageReference Include="Build5Nines.SharpVector" Version="[2.0.3,3.0.0)" />
2829
<PackageReference Include="OpenAI" Version="[2.1.0,3.0.0]" />
30+
<!-- <ProjectReference Include="..\Build5Nines.SharpVector\Build5Nines.SharpVector.csproj" /> -->
2931
</ItemGroup>
3032
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Build5Nines LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/Build5Nines.SharpVector/Build5Nines.SharpVector.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
<Description>Lightweight In-memory Vector Database to embed in any .NET Applications</Description>
1414
<Copyright>Copyright (c) 2025 Build5Nines LLC</Copyright>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
<PackageLicenseUrl>https://github.com/Build5Nines/SharpVector/blob/main/LICENSE</PackageLicenseUrl>
16+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1717
<Authors>Chris Pietschmann</Authors>
1818
<Company>Build5Nines LLC</Company>
1919
<PackageTags>vector;search;database;data;rag;search;llm;generative ai;ai;genai</PackageTags>
2020
</PropertyGroup>
2121

2222
<ItemGroup>
2323
<None Include="docs/README.md" Pack="true" PackagePath="\"/>
24+
<None Include="docs/LICENSE" Pack="true" PackagePath="\"/>
2425
</ItemGroup>
2526
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Build5Nines LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)