txtai
txtai copied to clipboard
A .Net binding for txtai?
Hello community, it would be very nice to make a .Net binding. Where can I find a guide for that? So please if anyone can give me some instructions on how to get in that would be great. Of course, I would also like to know if this binding issue is only handled by maintainers or if it is something open to the community.
Thank you for reaching out. A .NET binding would be great.
Currently there are API bindings for Go, Java, JavaScript and Rust. If you're familiar with any of those languages, looking at those projects is the best resource on creating a new binding.
If you do end up creating a .NET binding, I'd be happy to add a link to it here - https://neuml.github.io/txtai/api/#supported-language-bindings
Hi, it's great. I shall to tell you that library is great job from you. As soon as possible I want to start develop a binding for .Net; now I am doing research how works the others bindings. So I going to bring news about this issue very soon.
Thank you for the kind words. Looking forward to hearing about the .NET bindings. Feel free to reach out if you have any questions.
I think rust is a suitable option to create the .NET interop. I wonder what others think?
I don't know about how to build .Net bindings from Rust source. Since I don't know Rust so I can't say if it's possible or feasible, I do know that there is an API for interoperability between .Net and other assemblies, especially dynamic link libraries using P/Invoke. My opinion is that as long as you can code in C#/VB.Net/F# to produce .Net assemblies, you're better off. Of course there are plenty of exceptions to this rule. But I don't think this is the case.
Thank you for the thoughts and comments on this. Originally when I saw this issue, I thought the bindings would be for the txtai API. Basically make these methods available over HTTP. Is the intention something else?
No, speed is the aim. Not WebAPI.
Basically make these methods available over HTTP. Is the intention something else?
Yes, I thought the same thing, this is the idea that I have, it's basically to make a HTTP client to request the txtai server, or not?
In this case, I just need schemas to code a client for txtai over HTTP, but it's here: https://neuml.github.io/txtai/api/methods/ The above link is very important to understand how to code a HTTP client.
Hi guys, I bring a code to show how I going to make my solution:
public class Similarity
{
/// <summary>
/// The client used to communicate with the TxtAI API.
/// </summary>
private readonly HttpClient client;
/// <summary>
/// The serializer used to serialize and deserialize the JSON.
/// </summary>
private readonly IApiSerializer serializer;
/// <summary>
/// Construct to inject HttpClient.
/// </summary>
/// <param name="client">HttpClient</param>
public Similarity(HttpClient client, IApiSerializer serializer) {
this.client = client;
this.serializer = serializer;
}
/// <summary>
/// Computes the similarity between query and list of text. Returns a list of
/// {id: value, score: value} sorted by highest score, where id is the index
/// in texts.
/// </summary>
/// <param name="query">The text to be compared.</param>
/// <param name="texts">list of text.</param>
/// <returns>list of <see cref="IndexResult"/></returns>
public async Task<List<IndexResult>> SimilarityRequest(string query, List<string> texts) {
// convert to json the query and texts
var body = new {
query,
texts
};
// serialize the json
var json = this.serializer.Serialize(body);
// post the json to the TxtAI API
var response = await this.client.PostAsync("/similarity", new StringContent(json, System.Text.Encoding.UTF8, "application/json"));
// deserialize the json
return this.serializer.Deserialize<List<IndexResult>>(await response.Content.ReadAsStringAsync());
}
/// <summary>
/// Computes the similarity between list of queries and list of text. Returns a list
/// * of {id: value, score: value} sorted by highest score per query, where id is the
/// * index in texts.
/// </summary>
/// <param name="queries">list of text.</param>
/// <param name="texts">list of text.</param>
/// <returns>list of <see cref="IndexResult"/></returns>
public async Task<List<IndexResult>> SimilarityRequest(List<string> queries, List<string> texts) {
// convert to json the queries and texts
var body = new {
queries,
texts
};
// serialize the json
var json = this.serializer.Serialize(body);
// post the json to the TxtAI API
var response = await this.client.PostAsync("/similarity", new StringContent(json, System.Text.Encoding.UTF8, "application/json"));
// deserialize the json
return this.serializer.Deserialize<List<IndexResult>>(await response.Content.ReadAsStringAsync());
}
}
I will declare consts to http path
, at the moment this may be the final results, the java binding help me a lot 'cause is a type static language like C#, so I think that this is the most coherent about other bindings.
Please, give me feedback, If is this correct I going to finish really soon.
This looks great @oliver021. Once you have a GitHub repo ready, let me know and I'll take a look.
Hi David, this is a initial view of the final job, I can't test all methods but you can take a look now. https://github.com/oliver021/txtai.net
Thank you @oliver021! I'll take a look at the project and try to get it up and running. Will let you know.
Hi David, how you look the project?
Thank you for following up.
I have taken a look at the code and it all looks like it would work. I just haven't have the time to spin up a .NET environment to test it out but plan to do so within the next week.
Thank you.
I am very interested in this project, txtai is a really good work. So I will continue follow up.
Hi @oliver021, I've dug through the code in more detail and it looks like it is porting everything over as I would expect. Thank you once again for putting this together!
Do you have instructions on how to get this up and running? I see the solution files in the project but the README is empty. Did you intend for this library to be cross platform (i.e. can a developer on Linux use it?)? Is Visual Studio the only option to compile or can it be done other ways?
Yes David, there are severals options to run this code, It's cross platform too. Le me prepare instructions for you,
Thank you!
Hello, just wanted to follow up and see if this was still planned.
Closing due to inactivity