Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions dev-share-api/Configuration/VectorDbSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace DevShare.Api.Configuration;

public class VectorDbSettings
{
public const string SectionName = "VectorDb";

// Collections
public string ResourceCollection { get; set; } = "DevShare_Resource";
public string InsightCollection { get; set; } = "DevShare_Insight";

// Vector dimensions
public uint Dimensions { get; set; } = 384; // MiniLM-L6-v2 dimension

// Thresholds
public float DenseScoreThreshold { get; set; } = 0.65f; // Balanced semantic similarity
public float SparseScoreThreshold { get; set; } = 0.15f; // Good token overlap
public float HybridScoreThreshold { get; set; } = 0.53f; // Optimal fusion threshold

// Vector configurations
public VectorConfig Dense { get; set; } = new();
public VectorConfig Sparse { get; set; } = new();
}

public class VectorConfig
{
public string Name { get; set; } = string.Empty;
public bool OnDisk { get; set; }
public ulong MinTokenLength { get; set; } = 2;
public ulong MaxTokenLength { get; set; } = 10;
}
9 changes: 8 additions & 1 deletion dev-share-api/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,14 @@ public async Task<ActionResult<float[]>> InitVectorDB()
return Ok();
}

[HttpPost("embedding/indexing")]
[HttpPut("vector/updateCollection")]
public async Task<ActionResult<float[]>> UpdateCollection([FromBody] string collectionName)
{
await _vectorService.UpdateCollectionAsync(collectionName);
return Ok();
}

[HttpPost("vector/indexing")]
public async Task<ActionResult<UpdateResult>> Indexing([FromBody] string collectionName, string field)
{
return Ok(await _vectorService.IndexingAsync(collectionName, field));
Expand Down
6 changes: 5 additions & 1 deletion dev-share-api/Handle/SummarizeShareChainHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ public override async Task<bool> IsSkip(ResourceShareContext context)

protected override async Task<HandlerResult> ProcessAsync(ResourceShareContext context)
{
if (string.IsNullOrWhiteSpace(context.ExtractResult))
{
return HandlerResult.Fail("No content provided for summarization");
}

var summary = await _summaryService.SummarizeAsync(context.ExtractResult);
context.Summary = summary.Summary;
context.Title = summary.Title;
return HandlerResult.Success();
}

}
5 changes: 5 additions & 0 deletions dev-share-api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using DevShare.Api.Configuration;

var builder = WebApplication.CreateBuilder(args);

// Configuration
Expand All @@ -20,6 +22,9 @@
.AddInfrastructureServices(builder.Configuration)
.AddApplicationServices();

builder.Services.Configure<VectorDbSettings>(
builder.Configuration.GetSection(VectorDbSettings.SectionName));

var app = builder.Build();

// Middleware Configuration
Expand Down
4 changes: 3 additions & 1 deletion dev-share-api/Services/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static IServiceCollection AddInfrastructureServices(

// Database
services.AddDbContext<DevShareDbContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
{
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
});


// HTTP Client
Expand Down
33 changes: 21 additions & 12 deletions dev-share-api/Services/SummaryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ public SummaryService(AzureOpenAIClient openAIClient)

public async Task<SummaryResult> SummarizeAsync(string content)
{

var messages = new List<ChatMessage>
{
new SystemChatMessage($@"
You are a helpful summarization assistant.
new SystemChatMessage(@"
You are a specialized AI assistant focused on technical content summarization.

Your task is to:
1. Summarize the article in no more than 100 words.
2. Extract or infer a clear, appropriate title, no more than 12 words.
1. Create a semantically-rich summary that:
- Preserves key technical terms and domain-specific vocabulary
- Maintains semantic relationships between concepts
- Uses clear, factual language without metaphors
- Includes important numerical values and specific details
- Maximum length: 100 words
- Format: Single paragraph, no bullets

2. Extract or create a clear, appropriate title (max 12 words)

Always call the `generate_summary` function with your result in JSON:
{{
Expand All @@ -38,23 +45,25 @@ 1. Summarize the article in no more than 100 words.
}}

Guidelines:
- Avoid fabricating content. Be brief and accurate. Do not include any explanation.
- If the article lacks detail, summarize what’s available.
- Focus on technical accuracy and clarity
- Preserve key technical concepts and relationships
- Avoid explanations or additional formatting
- Be concise but informationally dense
- Never return plain text. Always return structured JSON using the `generate_summary` function.
"),
"),
new UserChatMessage(content)
};

var tool = CreateGenerateSummaryTool();

return await CallToolAndDeserializeAsync<SummaryResult>(
toolFunctionName: "generate_summary",
messages: messages,
tool: tool
);

}


private ChatTool CreateGenerateSummaryTool()
{
Expand All @@ -81,7 +90,7 @@ private ChatTool CreateGenerateSummaryTool()
})
);
}

public async Task<T> CallToolAndDeserializeAsync<T>(
string toolFunctionName,
List<ChatMessage> messages,
Expand Down
Loading
Loading