Skip to content

Commit

Permalink
Added XML comments
Browse files Browse the repository at this point in the history
  • Loading branch information
luisquintanilla committed Jul 30, 2024
1 parent 15e59a8 commit 05fe0ce
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/LlamaIndex.Core/Retrievers/BaseRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@

namespace LlamaIndex.Core.Retrievers
{
/// <summary>
/// Provides an abstraction for retreivers that retrieve nodes from a data source.
/// </summary>
public abstract class BaseRetriever
{

/// <summary>
/// Given a query, retrieves nodes from the data source.
/// </summary>
/// <param name="query">An input query used to retreive similar nodes.</param>
/// <param name="cancellationToken">Propagates notification for operations to be cancelled.<see cref="CancellationToken"/> </param>
/// <returns>A collection of nodes. See <see cref="NodeWithScore"/></returns>
public Task<NodeWithScore[]> RetrieveAsync(string query, CancellationToken cancellationToken = default)
{
return RetrieveNodesAsync(query, cancellationToken);
Expand Down
11 changes: 11 additions & 0 deletions src/LlamaIndex.Core/Retrievers/BaseRetrieverClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@

namespace LlamaIndex.Core.Retrievers;

/// <summary>
/// A client for retrieving nodes from a data source.
/// </summary>
/// <param name="host">The URI host for the data source</param>
/// <param name="vectorDbCollectionName">The name of the collection where nodes are stored.</param>
public class RetrieverClient(Uri host, string vectorDbCollectionName) : BaseRetriever
{
/// <summary>
/// Retrieves nodes from the data source.
/// </summary>
/// <param name="query">An input query used to retreive similar nodes.</param>
/// <param name="cancellationToken">Propagates notification for operations to be cancelled.<see cref="CancellationToken"/> </param>
/// <returns>A collection of nodes. See <see cref="NodeWithScore"/></returns>
protected override async Task<NodeWithScore[]> RetrieveNodesAsync(string query, CancellationToken cancellationToken)
{
var client = new HttpClient();
Expand Down
16 changes: 16 additions & 0 deletions src/LlamaIndex.Core/Schema/BaseNodeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@

namespace LlamaIndex.Core.Schema;

/// <summary>
/// Converts nodes to and from JSON.
/// </summary>
public class BaseNodeConverter : JsonConverter<BaseNode>
{
/// <summary>
/// Checks whether a node can be converted into the specified type.
/// </summary>
/// <param name="typeToConvert">The type to convert the node into.</param>
/// <returns>Whether the node can be converted into the specified type</returns>
public override bool CanConvert(Type typeToConvert)
{
return typeof(BaseNode).IsAssignableFrom(typeToConvert);
}

/// <summary>
///
/// </summary>
/// <param name="reader">The JSON reader <see cref="Utf8JsonReader"/></param>
/// <param name="typeToConvert">The type to convert the node into.</param>
/// <param name="options">JSON serialization options. <see cref="JsonSerializerOptions"/></param>
/// <returns>A <see cref="BaseNode"/></returns>
/// <exception cref="NotSupportedException"></exception>
public override BaseNode Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var jsonDoc = JsonDocument.ParseValue(ref reader);
Expand Down
7 changes: 7 additions & 0 deletions src/LlamaIndex.Core/Schema/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

namespace LlamaIndex.Core.Schema;

/// <summary>
/// Represents a document node.
/// </summary>
/// <param name="id">The node ID</param>
/// <param name="text">The text contents of a node</param>
/// <param name="mimeType">The data type represented in the node</param>
/// <param name="metadata">Additional metadata for the node</param>
public class Document(
string id,
string? text = null,
Expand Down
11 changes: 11 additions & 0 deletions src/LlamaIndex.Core/Schema/ImageDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

namespace LlamaIndex.Core.Schema;

/// <summary>
/// Represents an image node.
/// </summary>
/// <param name="id">The node ID</param>
/// <param name="text">A text description of the image. For example, alt-text.</param>
/// <param name="image">A string representation of the image.</param>
/// <param name="imagePath">A file path where the image is located.</param>
/// <param name="imageUrl">A URL where the image is located.</param>
/// <param name="imageMimetype">The mime type for the image.</param>
/// <param name="mimeType">The mime type for the node.</param>
/// <param name="metadata">Additional node metadata.</param>
public class ImageDocument(
string id,
string? text = null,
Expand Down
3 changes: 3 additions & 0 deletions src/LlamaIndex.Core/Schema/NodeType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace LlamaIndex.Core.Schema;

/// <summary>
/// Represents the type of node.
/// </summary>
public enum NodeType
{
TextNode = 1,
Expand Down
6 changes: 6 additions & 0 deletions src/LlamaIndex.Core/Schema/RelatedNodeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

namespace LlamaIndex.Core.Schema;

/// <summary>
/// Represents a related node.
/// </summary>
/// <param name="nodeId">The node ID.</param>
/// <param name="nodeType">The node type. <see cref="NodeType"/></param>
/// <param name="metadata">Additional node metadata.</param>
public class RelatedNodeInfo(string nodeId, NodeType nodeType, Dictionary<string, object>? metadata = null)
{
public string NodeId { get; } = nodeId;
Expand Down
18 changes: 18 additions & 0 deletions src/LlamaIndex.Core/Schema/RelationshipType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace LlamaIndex.Core.Schema;

/// <summary>
/// Represents the type of relationship between nodes.
/// </summary>
public enum RelationshipType
{
Source = 1,
Expand All @@ -11,8 +14,17 @@ public enum RelationshipType
Child = 5
}

/// <summary>
/// Provides extension methods for <see cref="RelationshipType"/>.
/// </summary>
public static class RelationshipTypeExtensions
{
/// <summary>
/// Converts a <see cref="RelationshipType"/> to a relationship name.
/// </summary>
/// <param name="relationshipType">The <see cref="RelationshipType"/></param>
/// <returns>The name of the relationship type.</returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static string ToRelationshipName(this RelationshipType relationshipType)
{
return relationshipType switch
Expand All @@ -26,6 +38,12 @@ public static string ToRelationshipName(this RelationshipType relationshipType)
};
}

/// <summary>
/// Converts a <see cref="RelationshipType"/> to a relationship key.
/// </summary>
/// <param name="relationshipType">The <see cref="RelationshipType"/></param>
/// <returns>The key of the relationship type.</returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static string ToRelationshipKey(this RelationshipType relationshipType)
{
return relationshipType switch
Expand Down
20 changes: 20 additions & 0 deletions src/LlamaIndex.Core/Schema/TextNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

namespace LlamaIndex.Core.Schema;

/// <summary>
/// Represents a text node.
/// </summary>
/// <param name="id">The node ID.</param>
/// <param name="text">The text contents of the node.</param>
/// <param name="startCharIndex">The index where the node starts.</param>
/// <param name="endCharIdx">The index where the node ends.</param>
/// <param name="mimeType">The node mime type.</param>
/// <param name="metadata">Additional node metadata</param>
[JsonConverter(typeof(BaseNodeConverter))]
public class TextNode(
string id,
Expand All @@ -19,6 +28,17 @@ public class TextNode(
public string? MimeType { get; } = mimeType;
}

/// <summary>
/// Represents an image node.
/// </summary>
/// <param name="id">The node ID</param>
/// <param name="text">The text description of the image.</param>
/// <param name="image">The representation of the image.</param>
/// <param name="imagePath">The file path image location.</param>
/// <param name="imageUrl">The URL image location.</param>
/// <param name="imageMimetype">The mime type of the image.</param>
/// <param name="mimeType">The mime type of the node.</param>
/// <param name="metadata">Additional node metadata.</param>
[JsonConverter(typeof(BaseNodeConverter))]
public class ImageNode(
string id,
Expand Down
3 changes: 3 additions & 0 deletions src/LlamaParse/ItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace LlamaParse;

/// <summary>
/// Represents the type of item in a document.
/// </summary>
[Flags]
public enum ItemType
{
Expand Down
3 changes: 3 additions & 0 deletions src/LlamaParse/Languages.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace LlamaParse;

/// <summary>
/// The languages supported by LlamaParse.
/// </summary>
public enum Languages
{
Baza,
Expand Down
26 changes: 24 additions & 2 deletions src/LlamaParse/LlamaParseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@

namespace LlamaParse;

/// <summary>
/// The LlamaParseClient class provides methods for parsing data from files using the LlamaParse service.
/// </summary>
public partial class LlamaParseClient
{
internal Configuration Configuration { get; }

private readonly LlamaParseApiClient _client;

/// <summary>
/// The LlamaParseClient constructor.
/// </summary>
/// <param name="client">The <see cref="HttpClient"/> used to make requests to the LlamaParse service.</param>
/// <param name="configuration">The LlamaParse <see cref="Configuration"/></param>
/// <exception cref="ArgumentException"></exception>
public LlamaParseClient(HttpClient client, Configuration configuration)
{
if (string.IsNullOrWhiteSpace(configuration.ApiKey))
Expand Down Expand Up @@ -112,7 +121,7 @@ public async IAsyncEnumerable<RawResult> LoadDataRawAsync(
/// <param name="resultType">The type of result to retrieve. (Optional) <see cref="ResultType"/></param>
/// <param name="metadata">Additional metadata for the document. (Optional)</param>
/// <param name="language">Language (Optional)</param>
/// <param name="cancellationToken">The cancellation token. (Optional)</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> (Optional)</param>
/// <returns>An asynchronous enumerable of RawResult objects representing the loaded data.</returns>
public async IAsyncEnumerable<RawResult> LoadDataRawAsync(
IEnumerable<FileInfo> files,
Expand Down Expand Up @@ -156,7 +165,7 @@ public async IAsyncEnumerable<RawResult> LoadDataRawAsync(
/// Loads images from a document asynchronously.
/// </summary>
/// <param name="document">The document containing the image metadata. <see cref="Document"/></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param>
/// <returns>An asynchronous enumerable of ImageDocument objects representing the loaded images.</returns>
public async IAsyncEnumerable<ImageDocument> LoadImagesAsync(Document document, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Expand All @@ -169,13 +178,26 @@ public async IAsyncEnumerable<ImageDocument> LoadImagesAsync(Document document,
}
}

/// <summary>
/// Loads images from a document asynchronously.
/// </summary>
/// <param name="rawResult">The <see cref="RawResult"/> from a parsing job.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param>
/// <returns>An asynchronous enumerable of ImageDocument objects representing the loaded images.</returns>
public IAsyncEnumerable<ImageDocument> LoadImagesAsync(RawResult rawResult, CancellationToken cancellationToken = default)
{
var jobId = rawResult.JobId;

return LoadImagesAsync(jobId, rawResult.Metadata, cancellationToken);
}

/// <summary>
/// Loads images from a document asynchronously.
/// </summary>
/// <param name="jobId">The parse job ID</param>
/// <param name="documentMetadata">Additional document metadata.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param>
/// <returns></returns>
public async IAsyncEnumerable<ImageDocument> LoadImagesAsync(string jobId, Dictionary<string, object>? documentMetadata = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var metadata = documentMetadata ?? new Dictionary<string, object>();
Expand Down
3 changes: 3 additions & 0 deletions src/LlamaParse/LlamaParseClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace LlamaParse;

/// <summary>
/// The LlamaParseClientExtensions class provides extension methods for the LlamaParseClient class.
/// </summary>
public static class LlamaParseClientExtensions
{
/// <summary>
Expand Down

0 comments on commit 05fe0ce

Please sign in to comment.